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
|
||||||
|
|
||||||
|
@ -50,8 +51,10 @@ 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])
|
||||||
|
|
||||||
|
@ -60,6 +63,8 @@ def enumIpUnix():
|
||||||
|
|
||||||
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