python获取远程设备的IP地址

2015-05-11 0 631
python获取远程设备的IP地址

有时需要将主机名转换成对应的IP地址,例如快速查询域名。假如将域名改一个不存在的域名,try-except块会捕捉错误,向用户显示一个错误信息。

    import socket  
    def get_remote_machine_info():  
        remote_host = 'www.python.org'  
        try:  
            print "IP address:%s" %socket.gethostbyname(remote_host)  
        except socket.error,err_msg:  
            print "%s:%s"%(remote_host,err_msg)  
      
      
    if __name__ == "__main__":  
        get_remote_machine_info()  

遇见资源网 python python获取远程设备的IP地址 http://www.ox520.com/15300.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务