Code Junkie

In the last year, I’ve spent a bit of time learning and building with Python. So much so, that I’ve actually written a fully fleshed out application for work that makes short work of what used to take a long time manually. I’ve been finding every excuse to write Python code. Video download/processing? Sure. Rewriting my Jarvis to use both Applescript and Python, why not? I’m getting there though. (more details here:

Python is really a fun language to write with. I’ll post some more project information as time goes by.

I’ve been a code junkie recently.

So, recently I have been doing a lot of coding, both bash and php/html. The other day I was at work and a co-worker of mine who handles abuse complaints mentioned he had to process over 100 domains for something he was working on. I instantly thought about writing code to accomplish it, I asked what he needed off of the domains, to which he responded IP and who owns it.

At first I started with a pretty simple script, with two domains hard coded into the script for testing purposes, which worked decently. 

Here is the original script.

foreach($x as $host){
$ip = gethostbyname($host);

echo “$host – $ip”;
echo “<br />”;



While this works, it was missing a few things, it would be really difficult to enter all 100 domains, each needing to be separated by a comma and wrapped in quotes, just a little too much work for me. Plus it doesn’t have the whois information. So, onward I go.


My second incarnation of the script allows for user entry of the domains, the only thing that’s needed is a comma separated list.

Here is the second script.

<form name=”list” action”” method=”post”>
<input type=”text” name=”list”>
<input type=”submit” name=”submit” value=”Submit”>
$list = $_POST[‘list’];

$listreturn = explode(‘,’, $list);
foreach($listreturn as $host){
$ip = gethostbyname($host);

$whois = shell_exec(‘whois -h ‘ . $ip);
$result = preg_match(‘/^OrgName:s*(.+)$/m’, $whois, $matches);
$org = $matches[1];
echo “$host – $ip – <b>$org</b>”;
echo “<br />”;


This script offers the ability to have a list of comma separated domains and it does all the work for you. It takes the domains, gets the IP address of the domain and then does a whois on that IP address to determine who owns the IP and then presents a nice list of information.

Within an hour I had the second version up and running and about 5 minutes later the list of domains that my co-worker had compiled, was processed and done.