MCPcopy
hub / github.com/Xyntax/POC-T / IP

Class IP

thirdparty/IPy/IPy.py:789–1013  ·  view source on GitHub ↗

Class for handling IP addresses and networks.

Source from the content-addressed store, hash-verified

787
788
789class IP(IPint):
790 """Class for handling IP addresses and networks."""
791
792 def net(self):
793 """Return the base (first) address of a network as an IP object.
794
795 The same as IP[0].
796
797 >>> IP('10.0.0.0/8').net()
798 IP('10.0.0.0')
799 """
800 return IP(IPint.net(self), ipversion=self._ipversion)
801
802 def broadcast(self):
803 """Return the broadcast (last) address of a network as an IP object.
804
805 The same as IP[-1].
806
807 >>> IP('10.0.0.0/8').broadcast()
808 IP('10.255.255.255')
809 """
810 return IP(IPint.broadcast(self))
811
812 def netmask(self):
813 """Return netmask as an IP object.
814
815 >>> IP('10.0.0.0/8').netmask()
816 IP('255.0.0.0')
817 """
818 return IP(IPint.netmask(self), ipversion=self._ipversion)
819
820 def _getIPv4Map(self):
821 if self._ipversion != 6:
822 return None
823 if (self.ip >> 32) != 0xffff:
824 return None
825 ipv4 = self.ip & MAX_IPV4_ADDRESS
826 if self._prefixlen != 128:
827 ipv4 = '%s/%s' % (ipv4, 32-(128-self._prefixlen))
828 return IP(ipv4, ipversion=4)
829
830 def reverseNames(self):
831 """Return a list with values forming the reverse lookup.
832
833 >>> IP('213.221.113.87/32').reverseNames()
834 ['87.113.221.213.in-addr.arpa.']
835 >>> IP('213.221.112.224/30').reverseNames()
836 ['224.112.221.213.in-addr.arpa.', '225.112.221.213.in-addr.arpa.', '226.112.221.213.in-addr.arpa.', '227.112.221.213.in-addr.arpa.']
837 >>> IP('127.0.0.0/24').reverseNames()
838 ['0.0.127.in-addr.arpa.']
839 >>> IP('127.0.0.0/23').reverseNames()
840 ['0.0.127.in-addr.arpa.', '1.0.127.in-addr.arpa.']
841 >>> IP('127.0.0.0/16').reverseNames()
842 ['0.127.in-addr.arpa.']
843 >>> IP('127.0.0.0/15').reverseNames()
844 ['0.127.in-addr.arpa.', '1.127.in-addr.arpa.']
845 >>> IP('128.0.0.0/8').reverseNames()
846 ['128.in-addr.arpa.']

Callers 12

__init__Method · 0.85
__add__Method · 0.85
__contains__Method · 0.85
overlapsMethod · 0.85
netMethod · 0.85
broadcastMethod · 0.85
netmaskMethod · 0.85
_getIPv4MapMethod · 0.85
make_netMethod · 0.85
__getitem__Method · 0.85
v46mapMethod · 0.85
_remove_subprefixFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected