Math using awk

Awk has built-in functionality to perform math with variables derived from a line. For example, let’s take a look at the output of df:

# df /
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 1942608 311772 1630836 16% /

To figure out the percentage used, simply take the available and divide that by the used. Using sed to trim off the header then piping the output to awk and adding a “%” string at the end of the calculation:

# df / | sed '1,1d' | awk '{print $3/$2*100"%"}'


For more information, please see The GNU Awk User’s Guide: Arithmetic Operators.

Read More

Hacking the Woshida T7866WIP HD IP Camera

I’m at it again with taking inexpensive cameras and pushing them to the limits; this time it’s with a Woshida T7866WIP IP camera and uncovering undocumented functionality through curiosity, exploration, hacking, and reverse engineering. This camera resembles that of my Foscam clone which is nice when it comes to setting up a nicer remote interface or integrating with another security system. From the overall quality of the 720P video to the healthy click of the relay activating the IR LEDs, my overall experience with this camera leaves me wanting more of them! There are a few features, some of which are undocumented:

  • 720P video RTSP video stream
  • M-JPEG stream at 640×360 (VGA) or 320×180 (QVGA)
  • Micro-SD slot for recording video (continuous, scheduled, or alarm) and still photos (alarm)
  • ONV...
Read More

Flask Web Apps in OS X Server

So, you want to run your Python Flask web applications the native OS X Apache web server? Well that’s awesome, because so did I! This probably won’t work on 10.7.x and earlier without using Apache from brew/ports or using MAMP (which I used); I’m running OS X Yosemite 10.10.5 with the latest server application for this version of OS X.

vonavi:~ jamie$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.10.5
BuildVersion: 14F27

vonavi:~ jamie$ sudo serveradmin -v
Version 15S2259

Step 1: Choose where your app will live.
I personally chose “/Users/jamie/Sites/home” simply for ease of access but I’m not using the userdir functionality.

Here is how my app is laid out:
|-- _venv\
|-- app\
|-- static\
|-- templates\

Read More

SQLAlchemy: Connecting to pre-existing databases & table joins!

SqlAlchemy is an object-relational mapper (ORM), which means that it takes SQL constructs and makes them Python objects which can be manipulated natively. Most of the time the same code can be recycled to use multiple database back-ends (unless you use back-end specific features).

I will be using Microsoft SQL Server for this particular example and show you how to use a technique called database reflection to get table information from a database schema when the database and tables already exist. For this you will need SQLAlchemy and pymssql installed.

# -*- coding: utf-8 -*-

__author__ = "Jamie Ivanov"

from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine, MetaData, Table

def main():
engine = create_engine('mssql+pymssql://server/Databa...

Read More

Inside the Motorola Scout73/Foscam73/Blink HD security camera

Since I have not been able to successfully get access to the RTSP stream and the camera has been stuck in a reboot loop for a month after tinkering, I decided to go all-in and disassemble the camera in hopes of finding a place where I can serial in. I was hopeful after reading about the W55FA92 DEV-Board but it is never as simple as you want it to be. However, I’m far from done with this… I need to look at the pinouts for the N32926 chip and follow it to find were the serial pins may be so I can rig up a JTAG interface or fully destroy the contents of the memory and force it to reload maybe via TFTP.

NOTE: There is a lot of horrible soldering done inside this camera and a lot of corrosion that has affected the performance of the infrared LED’s so once this camera is revived then it will be...

Read More

Hacking the Motorola Scout73/Foscam73/Blink HD security camera

The Motorola Scout 73 HD is a network based 720p security camera with wifi, pan/tilt, 180 degree viewing, infrared night vision, and has a IP66 weatherproof housing. This sounds really nice especially for the price tag but you are forced into relying on a Monitor Everywhere solution which is absolutely ghastly to use. Basically this camera pushes a 720p live feed, and snapshots, to a Hubble RTMP server and Monitor Everywhere uses a Hubble API to fetch this information and send your mobile phone alerts.

The few problems I’ve experienced with it are that video playback is not full-screened which kind-of defeats the purpose of streaming in 720p, you cannot save videos which again defeats the purpose of streaming in 720p, there is a significant delay in controlling the camera due to going fro...

Read More

XML fun with Python and lxml’s objectify: Part 1.5: Advanced Parsing (XML, HTML, XHTML, oh my!)

There are dozens of scraping and parsing tools out there but sometimes they are too bloated or simply don’t do what you want them to do. Some may think this is the Rube Goldberg approach but this keeps you in absolute control and really isn’t as hard as it seems. This illustrates some of the features of lxml’s objectify which can be used to parse simple XML down to HTML/XHTML and broken variations.

For this example, I will be using the source code from You could use urllib or urllib2 to fetch the source and store it in a StringIO object. In this demonstration, I’ve loaded the source to in a StringIO object.

NOTE: Looking at the source, it kind-of makes my eyes want to bleed...

Read More

XML fun with Python and lxml’s objectify: Part 1: Parsing

I assume you’ve already read about lxml.objectify so I won’t bother being redundant but I am head-over-heels in love with it over lxml’s objectify. The goal of this is to be a supplement to lxml’s documentation and give real-world examples from my ETL experience using it. This is also assuming that you have some familiarity with Python and Python datatypes. With that quick blurb out of the way, let’s get to some fun!

For this work, I will be using a sample XML file (test.xml) consisting of:

The parser I will be using will require a file path or object but you can use a string parser if you are working with XML, XHTML, HTML, etc from other sources. First a parser needs to be created then objectify will parse the data against the parser...

Read More