Skip to content

Instantly share code, notes, and snippets.

@PSJoshi
Created October 2, 2015 06:50
Show Gist options
  • Select an option

  • Save PSJoshi/5a8a9325cca386afd77b to your computer and use it in GitHub Desktop.

Select an option

Save PSJoshi/5a8a9325cca386afd77b to your computer and use it in GitHub Desktop.
python:Check if ip is in a network
>>>from netaddr import IPNetwork, IPAddress
>>>if IPAddress("192.168.0.1") in IPNetwork("192.168.0.0/24"):
print "Yes!"
>>>import ipaddress
>>> ipaddress.ip_address('192.168.0.1') in ipaddress.ip_network('192.168.0.0/24')
True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment