update enumip for Python3 and 64 bit
This commit is contained in:
parent
3fe71a6f3b
commit
4acc003707
|
@ -1,6 +1,7 @@
|
|||
import socket
|
||||
import struct
|
||||
import array
|
||||
import sys
|
||||
|
||||
IOCTL_SIOCGIFCONF = 0x8912
|
||||
|
||||
|
@ -50,8 +51,10 @@ IOCTL_SIOCGIFCONF = 0x8912
|
|||
def enumIpUnix():
|
||||
import fcntl
|
||||
|
||||
inbytes = 128 * 32 # Maximum 128 interfaces
|
||||
ifreq = array.array('B', '\0' * inbytes)
|
||||
struct_size = 40 if (sys.maxsize > 2**32) else 32
|
||||
|
||||
inbytes = 128 * struct_size # Maximum 128 interfaces
|
||||
ifreq = array.array('B', b'\0' * inbytes)
|
||||
|
||||
ifconf = struct.pack('iL', inbytes, ifreq.buffer_info()[0])
|
||||
|
||||
|
@ -60,6 +63,8 @@ def enumIpUnix():
|
|||
|
||||
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']
|
||||
|
|
Loading…
Reference in New Issue