2.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 without creating IPv4 or IPv6 Object. These are desscribed as below.


2.1.1. bin_mask()

  • converts and provides binary mask

>>> bin_mask(24)
'255.255.255.0'

2.1.2. to_dec_mask()

  • exactly opposite of above

>>> to_dec_mask("255.255.255.0")
24

2.1.3. bin2dec()

  • decimal number of mask for provided binary mask input

>>> bin2dec('11111111111111111111111111110000')
4294967280

2.1.4. bin2decmask()

  • subnet-mask for provided binary mask input

>>> bin2decmask('11111111111111111111111111110000')
28

2.1.5. binsubnet()

  • binary representation of given subnet

>>> binsubnet('10.10.10.0/24')
'00001010000010100000101000000000'

2.1.6. dec2dotted_ip

  • converts decimal ip address to dotted decimal ip notation

>>> n = 183490304
>>> dec2dotted_ip(n)
'10.239.215.0'

2.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

2.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

2.1.9. 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}

2.1.10. 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

2.1.11. ns-lookup

  • Use the nslookup() to get the dns name programatically.

>>> nslookup("8.8.8.8")
'dns.google'

2.1.12. 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

2.1.13. inet_address

  • Use the inet_address() for converting cisco interface ip address to standard notation.

inet_address("192.168.100.3", "255.255.255.0")
'192.168.100.3/24'

2.1.14. get_inet_address

  • Use the get_inet_address() for getting standard notation of cisco interface primary ip address line.

get_inet_address("ip address 192.168.100.3 255.255.255.0 secondary")  ## Does Not returns
get_inet_address("ip address 192.168.100.3 255.255.255.0")
'192.168.100.3/24'

2.1.15. get_secondary_inet_address

  • Use the get_secondary_inet_address() for getting standard notation of cisco interface secondary ip address line.

get_secondary_inet_address("ip address 192.168.100.3 255.255.255.0")            ## Does Not returns
get_secondary_inet_address("ip address 192.168.100.3 255.255.255.0 secondary")
'192.168.100.3/24'

2.1.16. get_inetv6_address

  • Use the get_inetv6_address() for getting ipv6 address out from cisco interface command line.

  • link_local is an optional argument, to exclusively provide information if address is link-local or not.

get_inetv6_address("ipv6 address FE80::A link-local", link_local=True)
'FE80::A'
get_inetv6_address("ipv6 address 2620:123:4567::1:1:A/128", link_local=False)
'2620:123:4567::1:1:A/128'

2.1.17. get_subnet

  • Use the get_subnet() to get the subnet number from provided standard ipv4 ip/mask.

get_subnet("192.168.20.5/25")
'192.168.20.0/25'

2.1.18. get_v6_subnet

  • Use the get_v6_subnet() to get the subnet number from provided standard ipv6 ip/mask.

get_v6_subnet("2620:123:4567::1:1:A/64")
'2620:123:4567:0:0:0:0:0/64'

2.1.19. classful_subnet

  • Use the classful_subnet() to add classful subnet mask to provided ip (ipv4).

  • Do not provide ip with its existing mask, only ip address is required.

classful_subnet("10.10.20.4")
10.10.20.4/8
classful_subnet("192.168.20.2")
192.168.20.2/24
classful_subnet("172.17.20.2")
172.17.20.2/16