【问题标题】:how to check an ip address is local [duplicate]如何检查IP地址是本地的[重复]
【发布时间】:2016-08-28 06:24:54
【问题描述】:

代码如下:

def isSrsInternal(srcip):
    here i want to write code to check that srcip is local source to thet network  or not
    if srcip is local than it will return true 
    else return false

1 谁能给我写这个函数的想法

【问题讨论】:

    标签: python python-2.7


    【解决方案1】:

    您可以考虑使用ipaddress 模块:

    >>> import ipaddress
    >>> ip = ipaddress.IPv4Address('192.168.0.1')
    >>> ip2 = ipaddress.IPv4Address('64.233.160.143') #Google's IP address
    >>> ip.is_private
    True
    >>> ip2.is_private
    False
    

    【讨论】:

      猜你喜欢
      • 2012-06-06
      • 1970-01-01
      • 1970-01-01
      • 2012-01-24
      • 2012-08-03
      • 2013-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多