可以通过socket.getaddrinfo()函数查询出IP地址,如下例
#!/usr/bin/env python
# Basic getaddrinfo() basic example - Chapter 4 - getaddrinfo-basic.py
import sys, socket
result = socket.getaddrinfo(sys.argv[1], None)
print result[0][4]
运行如下:
$ ./getaddrinfo-basic.py www.yahoo.com
('216.109.118.71',0)
#!/usr/bin/env python
# Basic getaddrinfo() basic example - Chapter 4 - getaddrinfo-basic.py
import sys, socket
result = socket.getaddrinfo(sys.argv[1], None)
print result[0][4]
运行如下:
$ ./getaddrinfo-basic.py www.yahoo.com
('216.109.118.71',0)