如何检查IP地址是本地的

时间:2016-05-03 09:18:10

标签: python python-2.7

这是代码:

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任何人都可以给我写这个功能的想法

1 个答案:

答案 0 :(得分: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