__MagicPower
Do one thing and do it best!

导航

 
 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]

posted on 2015-12-21 14:38  __MagicPower  阅读(217)  评论(0编辑  收藏  举报