1.1. addressing - module functions
import addressing module from nettoolkit as below.
Functions of addressing will be available to be used than after.
>>> from nettoolkit.addressing import *
There are few addressing functions - which can be used after creating IPv4 or IPv6 Object. These are described in following two pages.
There are few addressing functions - which can be used without creating IPv4 or IPv6 Object. These are desscribed as below.
1.1.1. bin_mask()
converts and provides binary mask
>>> bin_mask(24) '255.255.255.0'
1.1.2. to_dec_mask()
exactly opposite of above
>>> to_dec_mask("255.255.255.0") 24
1.1.3. bin2dec()
decimal number of mask for provided binary mask input
>>> bin2dec('11111111111111111111111111110000') 4294967280
1.1.4. bin2decmask()
subnet-mask for provided binary mask input
>>> bin2decmask('11111111111111111111111111110000') 28
1.1.5. binsubnet()
binary representation of given subnet
>>> binsubnet('10.10.10.0/24') '00001010000010100000101000000000'
1.1.6. dec2dotted_ip
converts decimal ip address to dotted decimal ip notation
>>> n = 183490304 >>> dec2dotted_ip(n) '10.239.215.0'
1.1.7. subnet_size_to_mask
converts subnet size to get subnet mask value
>>> subnet_size_to_mask(256) 24 >>> subnet_size_to_mask(512) 23
1.1.8. inv_subnet_size_to_mask
converts inverse subnet to get subnet mask value
>>> inv_subnet_size_to_mask(255) 24 >>> inv_subnet_size_to_mask(511) 23
1.1.9. get_subnet
get subnet/mask from decimal network ip and size of subnet (unvalidated)
>>> get_subnet(183490304, 256) '10.239.215.0/24' >>> get_subnet(183490304, 512) Invalid subnet/mask cannot return 10.239.215.0/23 ''
1.1.10. ipv4_octets
get octets in a list for provided ip/subnet
>>> ipv4_octets("10.11.12.0/24") {'octets': ['10', '11', '12', '0'], 'mask': 24}
1.1.11. range_subset
check whether range1 is a subset of range2
>>> range_subset(range(0,50), range(0,100)) True >>> range_subset(range(0,120), range(0,100)) False
1.1.12. ns-lookup
Use the
nslookup()
to get the dns name programatically.>>> nslookup("8.8.8.8") 'dns.google'
1.1.13. IP.ping
Use the
IP.ping_average()
from nettoolkit to get the average responce time (in ms) for given ip.>>> IP.ping_average("8.8.8.8") 289