Sunday, September 20, 2009

How much time do I have?

Started an online java class (Berkley) and got a bit sidetracked. Received first "Hey, I haven't heard from you in two weeks; you know you've got six months to complete this thing" grams. Scared the hell out of me.

How bad off am I? There are ways to find this out from the shell, but Python is what I know, more specifically the datetime module:



[GCC 4.2.1 20070719 [FreeBSD]] on freebsd7
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> date2 = datetime.datetime(2010, 3, 4)
>>> date1 = datetime.datetime(2009, 9, 20)
>>> date2 - date1
datetime.timedelta(165)


Time to get on the stick. (Today's Sep. 20, end of all things is March 4 next year, 165 days to go to produce a lot of code that actually works and is designed right).

Notes:

My overuse of certain constructs and modules (datetime, list comprehensions) reminds me of a German penfriend I had in high school who described, somewhat distainfully, a visiting American German teacher, clearly full of himself, thusly:

Der typische Ami, der nur sieben Wörter Deutsch kann und sie immer wieder verwendet. (The typical Yank who knows seven words of German and uses them again and again).

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.