• python剑指网络


      

    >>> #获取hostname
    ... 
    >>> host_name=socket.gethostname()
    >>> print "%s" %host_name
    SimilarFacedeMacBook-Pro.local
    >>> #获取IP地址
    ... 
    >>> socket.gethostbyname(host_name)
    '192.168.30.120'
    
    #获取远程机器的IP,类型于ping
    import socket
    def get_remote_machine_info(remote_host):
        try:
            #SimilarFacedeMacBook-Pro:~ similarface$ ping www.python.org
            #PING python.map.fastly.net (103.245.222.223): 56 data bytes
            print("%s的IP地址:%s" %(remote_host,socket.gethostbyname(remote_host)))
        except socket.error,err_msg:
            print("%s: %s" %(remote_host,err_msg))
    #result:

        www.python.org的IP地址:103.245.222.223

      

      

  • 相关阅读:
    满血复活
    绝望,绝望、希望
    认真生活的态度
    星期一
    户外穿越
    认真准备
    早点休息
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
  • 原文地址:https://www.cnblogs.com/similarface/p/5521009.html
Copyright © 2020-2023  润新知