Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 6 commits
  • 3 files changed
  • 0 commit comments
  • 2 contributors
Commits on Sep 07, 2011
Victor Stinner Fix IP.__cmp__ if argument is not an IP
IP.__cmp__(other) doesn't raise an exception anymore if other is not an IP object
f05ac44
Victor Stinner Add IP.get_mac() method: get the 802.3 MAC address from IPv6 RFC 2464…
… address
87993b4
Victor Stinner only __eq__ accepts non-IP objects, not __lt__ fbeec02
Victor Stinner Add IP.__ne__(other) method b1e1d7a
Commits on May 16, 2012
@haypo haypo Fix ipversion in IP.__getitem__()
Issue #12: Fix IP('::/0')[0]: return an IPv6 instead of an IPv4 address
1e8866d
Commits on Jun 19, 2012
@d1b Merge branch 'master' of https://github.com/haypo/python-ipy 46784bc
Showing with 64 additions and 3 deletions.
  1. +5 −1 ChangeLog
  2. +26 −2 IPy.py
  3. +33 −0 test/test.rst
View
6 ChangeLog
@@ -1,7 +1,11 @@
Version 0.76 (under development)
--------------------------------
-(no change yet)
+* ip == other and ip != other doesn't fail with an exception anymore if other
+ is not a IP object
+* Add IP.get_mac() method: get the 802.3 MAC address from IPv6 RFC 2464
+ address.
+* Fix IP('::/0')[0]: return an IPv6 instead of an IPv4 address
Version 0.75 (2011-04-12)
-------------------------
View
28 IPy.py
@@ -705,7 +705,6 @@ def __cmp__(self, other):
0
"""
-
# Im not really sure if this is "the right thing to do"
if self._prefixlen < other.prefixlen():
return (other.prefixlen() - self._prefixlen)
@@ -744,8 +743,13 @@ def __cmp__(self, other):
return 0
def __eq__(self, other):
+ if not isinstance(other, IPint):
+ return False
return self.__cmp__(other) == 0
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
def __lt__(self, other):
return self.__cmp__(other) < 0
@@ -948,7 +952,7 @@ def __getitem__(self, key):
>>> print(str(ip[-1]))
127.0.0.3
"""
- return IP(IPint.__getitem__(self, key))
+ return IP(IPint.__getitem__(self, key), ipversion=self._ipversion)
def __repr__(self):
"""Print a representation of the Object.
@@ -975,6 +979,26 @@ def __add__(self, other):
ret._prefixlen = self.prefixlen() - 1
return ret
+ def get_mac(self):
+ """
+ Get the 802.3 MAC address from IPv6 RFC 2464 address, in lower case.
+ Return None if the address is an IPv4 or not a IPv6 RFC 2464 address.
+
+ >>> IP('fe80::f66d:04ff:fe47:2fae').get_mac()
+ 'f4:6d:04:47:2f:ae'
+ """
+ if self._ipversion != 6:
+ return None
+ if (self.ip & 0x20000ffff000000) != 0x20000fffe000000:
+ return None
+ return '%02x:%02x:%02x:%02x:%02x:%02x' % (
+ (((self.ip >> 56) & 0xff) & 0xfd),
+ (self.ip >> 48) & 0xff,
+ (self.ip >> 40) & 0xff,
+ (self.ip >> 16) & 0xff,
+ (self.ip >> 8) & 0xff,
+ self.ip & 0xff,
+ )
def _parseAddressIPv6(ipstr):
"""
View
33 test/test.rst
@@ -71,3 +71,36 @@ True
>>> IP('::ffff:128.0.0.0/103').reverseNames() == IP('128.0.0.0/7').reverseNames()
True
+Issue #2 and #9
+===============
+
+>>> IP('1.2.3.4') == None
+False
+>>> IP('1.2.3.4') == object()
+False
+>>> IP('1.2.3.4') != None
+True
+>>> IP('1.2.3.4') != object()
+True
+
+
+get_mac()
+=========
+
+>>> IP('fe80::f66d:04ff:fe47:2fae').get_mac()
+'f4:6d:04:47:2f:ae'
+>>> IP('2001:DB8::212:7FFF:FEEB:6B40').get_mac()
+'00:12:7f:eb:6b:40'
+>>> IP('::1').get_mac() is None
+True
+>>> IP('1.2.3.4').get_mac() is None
+True
+
+Issue #12: IPv6[index] -> IPv4
+==============================
+
+>>> IP('1.2.3.0/24')[4]
+IP('1.2.3.4')
+>>> IP('::/0')[1]
+IP('::1')
+

No commit comments for this range

Something went wrong with that request. Please try again.