0.0.0.0 (INADDR_ANY)은 "임의"주소 (라우팅 할 수없는 메타 주소)입니다. "모든 IPv4 인터페이스를 지정하는"방법입니다.
import array
import struct
import socket
import fcntl
SIOCGIFCONF = 0x8912 #define SIOCGIFCONF
BYTES = 4096 # Simply define the byte size
# get_iface_list function definition
# this function will return array of all 'up' interfaces
def get_iface_list():
# create the socket object to get the interface list
sck = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# prepare the struct variable
names = array.array('B', '\0' * BYTES)
# the trick is to get the list from ioctl
bytelen = struct.unpack('iL', fcntl.ioctl(sck.fileno(), SIOCGIFCONF, struct.pack('iL', BYTES, names.buffer_info()[0])))[0]
# convert it to string
namestr = names.tostring()
# return the interfaces as array
return [namestr[i:i+32].split('\0', 1)[0] for i in range(0, bytelen, 32)]
# now, use the function to get the 'up' interfaces array
ifaces = get_iface_list()
# well, what to do? print it out maybe...
for iface in ifaces:
print iface
: 이것은 모든 인터페이스는 모든 네트워크 인터페이스를 나열하려면
포트 12345에 듣고 난 당신이 리눅스를 사용하는 경우이 작업을 수행 할 수 this
같은 라이브러리를 사용하는 것이 좋습니다 것을 의미