Acknowledgments Noahs Acknowledgments

As I sit writing an acknowledgment for this book, I have to first mention Dr. Joseph E. Bogen, because he made the single largest impact on me, at a time that it mattered the most. I met Dr. Bogen while I was working at Caltech, and he opened my eyes to another world giving me advice on life, psychology, neuroscience, math, the scientific study of consciousness, and much more. He was the smartest person I ever met, and was someone I loved. I am going to write a book about this experience...

Manual Information Gathering

Let's also look at the more complicated path of manually gathering information. By this, we mean information that you gather with your own eyes and key in with your own hands. Examples include a list of servers with corresponding IP addresses and functions, a list of contacts with email addresses, phone numbers, and IM screen names, or the dates that members of your team are planning to be on vacation. There are certainly tools available that can manage most, if not, all of these types of...

Python Builtins and Modules str

A string is simply a sequence of characters. If you ever need to deal with textual data, you'll almost certainly need to work with it as a string object or a series of string objects. The string type, str, is a powerful, flexible means for manipulating string data. This section shows you how to create strings and what you can do with them once they've been created. The most common way to create a string is to surround the text with quotation marks In 1 stringl 'This is a string' In 2 string2...

Scapy

If you like writing network code, you are going to love Scapy. Scapy is an incredibly handy interactive packet manipulation program and library. Scapy can discover networks, perform scans, traceroutes, and probes. There is also excellent documentation available for Scapy. If you like this intro, you should buy the book for even more details on Scapy. The first thing to figure out about Scapy is that, as of this writing, it is kept in a single file. You will need to download the latest copy of...

Using Return Codes with Subprocess

One interesting thing to note about subprocess.call is that you can use return codes to determine the success of your command. If you have experience with programming in C or Bash, you will be quite at home with return codes. The phrases exit code and return code are often used interchangeably to describe the status code of a system process. Every process will have a return code when it exits, and the status of the return code can be used to determine what actions a program should take....

Building an Apache Log Viewer Using Curses

Curses is a library that facilitates the creation of interactive text-based applications. Unlike GUI toolkits, curses does not follow an event handling and callback approach. You are responsible for getting input from the user and then doing something with it, whereas in GTK, the widget handles getting input from the user and the toolkit calls a handler function when an event occurs. Another difference between curses and GUI toolkits is that with GUI toolkits you are adding widgets to some...

Cross Platform Unix Programming in Python

While there are some significant differences between nix operating systems, there is much more in common that not. One way to bring the different versions of nix back together is to write cross-platform tools and libraries that bridge the divide between the operating system differences. One of the most basic ways to accomplish this is to write conditional statements that check for the operating systems, platform, and version in code that you write. Python takes the batteries included philosophy...

Graphical Images

The following two examples will continue the example of parsing an Apache logfile for the client IP address and the number of bytes that were transferred. In the previous section, our example generated a shelve file that contained some information that we want to share with other users. So, now, we will create a chart object from the shelve file to make the data easy to read usr bin env python shelve_file shelve.open 'access.s' items_list i l , i 0 for i in shelve_file.items bytes_sent i 0 for...

Python and NetSNMP

If you haven't done any SNMP development before, you may have gotten the impression that it is a bit nasty. Well, to be honest, it is. Dealing with SNMP is a bit of a pain, as it involves a very complex protocol, lots of RFCs to read, and a high chance for many things to go wrong. One way to diminish much of the initial pain of getting started with development is to use IPython to explore the SNMP code you will write and to get comfortable with the API. Example 7-1 is a very brief snippet of...