mirror of
https://git.photon.obnh.io/AXSY/whois.git
synced 2026-03-12 18:01:32 +00:00
Based on mwhois by Antonios A. Chariton Modifications for SCION AS support by Olaf Baumert, Axpo Systems AG
69 lines
1.2 KiB
Plaintext
69 lines
1.2 KiB
Plaintext
=Binary and numerical operations on IP addresses=
|
|
|
|
Copyright (c) 2008-2015, David P. D. Moss. All rights reserved.
|
|
|
|
{{{
|
|
|
|
>>> from netaddr import *
|
|
|
|
}}}
|
|
|
|
==Addition and Subtraction ==
|
|
|
|
{{{
|
|
|
|
>>> IPAddress('192.0.2.0') + 1
|
|
IPAddress('192.0.2.1')
|
|
|
|
>>> 1 + IPAddress('192.0.2.0')
|
|
IPAddress('192.0.2.1')
|
|
|
|
>>> IPAddress('192.0.2.1') - 1
|
|
IPAddress('192.0.2.0')
|
|
|
|
>>> IPAddress('192.0.0.0') + IPAddress('0.0.0.42')
|
|
IPAddress('192.0.0.42')
|
|
|
|
>>> IPAddress('192.0.0.42') - IPAddress('0.0.0.42')
|
|
IPAddress('192.0.0.0')
|
|
|
|
|
|
>>> 1 - IPAddress('192.0.2.1')
|
|
Traceback (most recent call last):
|
|
...
|
|
IndexError: result outside valid IP address boundary!
|
|
|
|
>>> ip = IPAddress('10.0.0.1')
|
|
>>> ip += 1
|
|
>>> ip
|
|
IPAddress('10.0.0.2')
|
|
>>> ip -= 1
|
|
>>> ip
|
|
IPAddress('10.0.0.1')
|
|
>>> ip += IPAddress('0.0.0.42')
|
|
>>> ip
|
|
IPAddress('10.0.0.43')
|
|
>>> ip -= IPAddress('0.0.0.43')
|
|
>>> ip
|
|
IPAddress('10.0.0.0')
|
|
|
|
}}}
|
|
|
|
==Binary operations==
|
|
|
|
{{{
|
|
|
|
>>> IPAddress('192.0.2.15') & IPAddress('255.255.255.0')
|
|
IPAddress('192.0.2.0')
|
|
|
|
>>> IPAddress('255.255.0.0') | IPAddress('0.0.255.255')
|
|
IPAddress('255.255.255.255')
|
|
|
|
>>> IPAddress('255.255.0.0') ^ IPAddress('255.0.0.0')
|
|
IPAddress('0.255.0.0')
|
|
|
|
>>> IPAddress('1.2.3.4').packed
|
|
b'\x01\x02\x03\x04'
|
|
|
|
}}}
|