update enumip for Python3 and 64 bit
This commit is contained in:
parent
3fe71a6f3b
commit
4acc003707
|
@ -1,6 +1,7 @@
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
import array
|
import array
|
||||||
|
import sys
|
||||||
|
|
||||||
IOCTL_SIOCGIFCONF = 0x8912
|
IOCTL_SIOCGIFCONF = 0x8912
|
||||||
|
|
||||||
|
@ -10,19 +11,19 @@ IOCTL_SIOCGIFCONF = 0x8912
|
||||||
# * for machine (useful for programs which
|
# * for machine (useful for programs which
|
||||||
# * must know all networks accessible).
|
# * must know all networks accessible).
|
||||||
# */
|
# */
|
||||||
#
|
#
|
||||||
# struct ifconf {
|
# struct ifconf {
|
||||||
# int ifc_len; /* size of associated buffer */
|
# int ifc_len; /* size of associated buffer */
|
||||||
# union {
|
# union {
|
||||||
# caddr_t ifcu_buf;
|
# caddr_t ifcu_buf;
|
||||||
# struct ifreq *ifcu_req;
|
# struct ifreq *ifcu_req;
|
||||||
# } ifc_ifcu;
|
# } ifc_ifcu;
|
||||||
#
|
#
|
||||||
# /*
|
# /*
|
||||||
# * Interface request structure used for socket
|
# * Interface request structure used for socket
|
||||||
# * ioctl's.
|
# * ioctl's.
|
||||||
# */
|
# */
|
||||||
#
|
#
|
||||||
# struct ifreq {
|
# struct ifreq {
|
||||||
# char ifr_name[16]; /* if name, e.g. "en0" */
|
# char ifr_name[16]; /* if name, e.g. "en0" */
|
||||||
# union {
|
# union {
|
||||||
|
@ -33,15 +34,15 @@ IOCTL_SIOCGIFCONF = 0x8912
|
||||||
# int ifru_metric;
|
# int ifru_metric;
|
||||||
# caddr_t ifru_data;
|
# caddr_t ifru_data;
|
||||||
# } ifr_ifru;
|
# } ifr_ifru;
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# /* Socket address, DARPA Internet style */
|
# /* Socket address, DARPA Internet style */
|
||||||
# struct sockaddr_in {
|
# struct sockaddr_in {
|
||||||
# short sin_family;
|
# short sin_family;
|
||||||
# unsigned short sin_port;
|
# unsigned short sin_port;
|
||||||
# struct in_addr sin_addr;
|
# struct in_addr sin_addr;
|
||||||
# char sin_zero[8];
|
# char sin_zero[8];
|
||||||
# };
|
# };
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# ioctl (fd, SIOCGIFCONF, &ifconf)
|
# ioctl (fd, SIOCGIFCONF, &ifconf)
|
||||||
|
@ -50,16 +51,20 @@ IOCTL_SIOCGIFCONF = 0x8912
|
||||||
def enumIpUnix():
|
def enumIpUnix():
|
||||||
import fcntl
|
import fcntl
|
||||||
|
|
||||||
inbytes = 128 * 32 # Maximum 128 interfaces
|
struct_size = 40 if (sys.maxsize > 2**32) else 32
|
||||||
ifreq = array.array('B', '\0' * inbytes)
|
|
||||||
|
inbytes = 128 * struct_size # Maximum 128 interfaces
|
||||||
|
ifreq = array.array('B', b'\0' * inbytes)
|
||||||
|
|
||||||
ifconf = struct.pack('iL', inbytes, ifreq.buffer_info()[0])
|
ifconf = struct.pack('iL', inbytes, ifreq.buffer_info()[0])
|
||||||
|
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
ifconf = fcntl.ioctl(s.fileno(), IOCTL_SIOCGIFCONF, ifconf)
|
ifconf = fcntl.ioctl(s.fileno(), IOCTL_SIOCGIFCONF, ifconf)
|
||||||
|
|
||||||
outbytes = struct.unpack('iL', ifconf)[0]
|
outbytes = struct.unpack('iL', ifconf)[0]
|
||||||
|
|
||||||
iplist = [socket.inet_ntoa(ifreq[i+20:i+24]) for i in range(0, outbytes, 32)]
|
iplist = [socket.inet_ntoa(ifreq[i+20:i+24]) for i in range(0,
|
||||||
|
outbytes,
|
||||||
|
struct_size)]
|
||||||
|
|
||||||
return [ip for ip in iplist if ip != '127.0.0.1']
|
return [ip for ip in iplist if ip != '127.0.0.1']
|
||||||
|
|
Loading…
Reference in New Issue