1 #!/usr/bin/env python 2 #--*-- coding:utf-8 --*-- 3 # Python Network Programming Cookbook -- Chapter – 1 4 # This program is optimized for Python 2.7. 5 # It may run on any other version with/without modifications. 6 import socket 7 def get_remote_machine_info(): 8 remote_host = 'www.python.org' 9 try: 10 print "IP address: %s" %socket.gethostbyname(remote_host) 11 except socket.error, err_msg: 12 print "%s: %s" %(remote_host, err_msg) 13 14 if __name__ == '__main__': 15 get_remote_machine_info()
TEST:
IP address: 23.235.43.223
[Finished in 0.1s]