import socket hostname = socket.gethostname() # print hostname ip = socket.gethostbyname(hostname) # print ip addrs = socket.getaddrinfo(hostname,None) for item in addrs: print item
C:\Python27\python.exe E:/python_demo/getip.py
(23, 0, 0, '', ('fe80::29d7:1a29:1c91:6ad3%34', 0, 0, 34))
(23, 0, 0, '', ('fe80::d824:8521:468:748d%28', 0, 0, 28))
(23, 0, 0, '', ('fe80::65f8:3fa7:13c0:72ac%27', 0, 0, 27))
(23, 0, 0, '', ('fe80::c528:3b54:c5b8:5752%26', 0, 0, 26))
(23, 0, 0, '', ('fe80::44a8:7f91:8fe6:c7bf%25', 0, 0, 25))
(23, 0, 0, '', ('fe80::bde7:1b2c:8cad:5ee%32', 0, 0, 32))
(23, 0, 0, '', ('fe80::71c3:29e:f56c:48ff%30', 0, 0, 30))
(23, 0, 0, '', ('fe80::755f:154c:394c:8d71%14', 0, 0, 14))
(23, 0, 0, '', ('fe80::48d:17e8:53ef:ee37%19', 0, 0, 19))
(2, 0, 0, '', ('192.168.100.1', 0))
(2, 0, 0, '', ('192.168.67.2', 0))
(2, 0, 0, '', ('192.168.196.1', 0))
(2, 0, 0, '', ('192.168.170.2', 0))
(2, 0, 0, '', ('192.168.56.1', 0))
(2, 0, 0, '', ('192.168.70.1', 0))
(2, 0, 0, '', ('192.168.174.1', 0))
(2, 0, 0, '', ('172.16.17.200', 0))
(23, 0, 0, '', ('2001:0:9d38:6ab8:48d:17e8:53ef:ee37', 0, 0, 0))