Sunday, September 13, 2009

Network Addressing (IPv4)

Part of the prep for the BSDA exam is a section on network addressing.

Python has at least three third party modules that cover this: IPy, netaddr, and ipaddr. I used IPy to study and learn the concepts of IPv4 network addresses. Here's a quick demo:


%python
Python 2.5.4 (r254:67916, Apr 13 2009, 18:09:11) 
[GCC 4.2.1 20070719 [FreeBSD]] on freebsd7  
Type "help", "copyright", "credits" or "license" for more information.
>>> import IPy
>>> subnetx = IPy.IP('192.168.127.0/24')
>>> subnetx.netmask()
IP('255.255.255.0')
>>> netmaskx = subnetx.netmask()
>>> netmaskx.strBin()
'11111111111111111111111100000000'
>>> netmaskx.strHex()
'0xffffff00'
>>> len(subnetx)
256
>>> subnetx.broadcast()
IP('192.168.127.255')
>>> subnetx[0]
IP('192.168.127.0')


And that's it. You have your CIDR defined input, the netmask in IP notation, the netmask in binary (helps in understanding - reminiscent of those T-shirts about 10 types of people in the world), and the netmask in hex.  At the end are the broadcast and network address.

Notes:

1) PEP 3144 is currently under review by the Python core developers for inclusion of an IP tool in the standard library. It's written by the author of ipaddr.

2) (shameless plug for BSDA exam) If you don't know Unix at all, and you're attempts to pick it up have failed, the exam forces you to learn some Unix sysadmin basics and demonstrate your proficiency. If you do know Unix, it may fill in some gaps. There is also a professional (advanced) version of the test under development. For $75, it's a steal, and much less than you would pay for a Microsoft exam (been there, done that). The exam prep page linked in this article (the BSD Wiki) is also a good place to visit to learn some of the things you (if you're like me) need to know, but don't.

3) Oddly, FreeBSD's ports system includes IPy under net-mgnt, netaddr under net, and ipaddr under devel.

4) I didn't cover IPv6.  That's something we'll all need to learn eventually.  There are projects like KAME and methods like tunneling that allow you to use and test IPv6.  I have not yet investigated them.

No comments:

Post a Comment