Scapy is a pretty cool tool for interacting with the network at a low level. I recently needed to test some iptables rules related to logging TCP resets, and Scapy made this trivial. There’s so much more you can do with Scapy… this post only scratches the surface.

System: Ubuntu 13.10

sudo apt-get install python-scapy

Run Scapy:

sudo scapy

Enter the IP information in the interactive shell:

>>> i = IP()
>>> i.dst = ""

Now enter the TCP information:

>>> t = TCP()
>>> t.dport = 443
>>> t.flags = "R"

The “R” flag is for RESET.

You can view the packet setup by typing:

>>> i.display()
>>> t.display()

If you’re happy with the configuration, you can send the packets by typing:

>>> sr1(i/t)

Note: That’s sr(one)… as in the number, not the letter ‘L’.


I use this trick to simulate a remote server being unavailable:

iptables -A OUTPUT -d -j DROP

Verify the firewall rule is present (with line numbers… makes deleting easier):

iptables -L OUTPUT --line-numbers

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source                  destination
1    DROP       all  --  anywhere      

To reenable traffic to the remote server, simply delete the firewall rule by line number:

iptables -D OUTPUT 1

Tagged with:  

The following command takes the output of the svn status command and creates a zip file containing all listed files whose status is not ‘?’:

svn st mycode | awk '!/^?/' | awk '{print $2}' | zip -@

Tagged with:  


ffmpeg -i input.mp4 -x264opts keyint=15:min-keyint=15 -c:v libx264 -preset slow -crf 22 output.mp4


Tagged with:  

HomebrewThe water report for Thornton, CO doesn’t contain all the information you need to properly adjust your water for home brewing. Fortunately, the water analysts for the city are very helpful. Here is an excerpt from the response I got when I asked for more details:

The City of Thornton does in fact have two separate water sources and we don’t always use both so the character of your water can actually vary a bit throughout the year. Thornton owns a significant share of the water in Standley Lake in Arvada. This water comes from Clear Creek. The Coors Beer commercials are accurate. This water is very clean and low in pollutants as I will summarize below.

Our second water source is the South Platte River. We divert water from the South Platte and store it in our gravel lakes until it is needed. While still better than many water sources, The South Platte is certainly exposed to more contaminants then our Standley Lake water.

In most years, water is drawn from Standley Lake nearly all year – only ceasing for maintenance to the treatment plant. Meanwhile, water from the South Platte is used to supplement our supply when demand spikes in the summertime.

Typically, we start using South Platte water in March and we might stop using it around October or November. This year we turned off our South Platte supply in late September, so the City is currently receiving only Standley Lake water. It is difficult to guess what ratio of our two water supplies you might receive at your residence when we do utilize both sources.

Now that you know the reasons behind the variability in Thornton’s water quality, I’ll throw several numbers at you which should represent your water quality at different times of year. These values were measured at a residence near your location that we sample year round. This residence is located near [redacted]. All values are in ppm:

Standley Lake (Winter) – Both (Summer) – South Platte Only
Calcium 56.3 85* 97.1
Magnesium 8.4 14* 18.1
Total Hardness 152 276 280
Calcium Hardness 100 200 236
Sulfate 51 92* 137
Chloride 36 76* 74
Bicarbonate 52.1 139.2 173.4

* = estimates based on the average of both sources during this time frame

Hopefully that’s enough detail to answer your questions. If you have any more questions or need more specific data certainly let me know and I’d be happy to help.

Tagged with:  

I wanted to play with Django recently, so I needed to enable python support in lighttpd. I found a few links about using the default lighttpd.conf file, but I have a custom (minimalist) lighttpd.conf file that I don’t want to pollute with unnecessary options. It turns out that enabling python support through mod_cgi is quite trivial:

1. Open lighttpd.conf

2. Add ".py" to the static-file.exclude-extensions variable to prevent people from viewing the raw python code:

static-file.exclude-extensions = ( ".py" )

3. Add "mod_cgi" to the server.modules variable:

server.modules = ( "mod_cgi" )

4. Add the association between *.py files and the python interpreter to the cgi.assign variable:

cgi.assign = ( ".py" => "/usr/bin/python" )

5. Make sure you have a “breakage” log defined… this helps debugging because python errors will get written here:

server.breakagelog = "/var/log/lighttpd/breakage.log"

6. Restart lighttpd

For more mod_cgi configuration options, read this.


There are a few ways on linux to see if the network stack is dropping packets, or just having problems in general:

1. ifconfig

 RX packets:522 errors:0 dropped:0 overruns:0 frame:0
 TX packets:406 errors:0 dropped:0 overruns:0 frame:0

2. cat /proc/net/dev

Inter-| Receive ... 
 face | bytes packets errs drop fifo frame ... 
 eth0:  87689 785 0 0 0 0 ...

3. cat /proc/net/udp

 so local_address rem_address ... drops
 277: 00000000:0044 00000000:0000 ... 0 

4. cat /proc/net/snmp

Tcp: ...
Udp: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors
Udp: 453 0 0 452 0 0

You can also see this on a per-process basis using cat /proc/<pid>/net/{udp,dev,snmp}

Check out iftop also.


Adding stdint.h to Visual Studio

On November 13, 2011, in Code Monkey, by Tom

Yes, stdint.h and inttypes.h are missing from Microsoft Visual Studio. As a result, anyone who’s written cross-platform C\C++ code for Windows has probably seen this error:

error C2146: syntax error : missing ';' before identifier 'foo'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

The fact is that Visual Studio doesn’t implement C99… it implements C89 (for compatibility reasons). So, you don’t have access to familiar types like:

  • int8_t, int16_t, int32_t, int64_t
  • uint8_t, uint16_t, uint32_t, uint64_t
  • INT8_MIN, INT8_MAX, etc
  • The fprintf macros PRId32, PRIu32, etc
  • strtoimax(), etc

Fortunately, Alexander Chemeris has written msinttypes: an implementation of stdint.h and inttypes.h for Microsoft Visual Studio. It is licensed under the BSD license, so the headers are actually usable commercially (no viral GPL). This following quote probably goes without saying (emphasis mine):

Note though, that just adding these headers does not make Visual Studio compiler fully C99 compliant.

This project has saved me a bunch of unwanted coding. Thanks Alex!

Tagged with:  

Here’s a video done by Ed Catmull (founder of Pixar) in 1972 while at the University of Utah. It’s purported to be the first digitally rendered film. It’s just amazing how far we’ve come since these early pioneering days.

The math that we take for granted for rendering 3D was being invented, real time, to create this video. (Ed’s credited for having working out that math to handle things like texture mapping, 3D anti-aliasing and z-buffering.)

The story behind the video and how it was found recently is pretty cool too. Props to Robby Ingebretsen for sharing this!

40 Year Old 3D Computer Graphics (Pixar, 1972) from Robby Ingebretsen on Vimeo.

Tagged with: