Archive for January, 2010

Motivation: Zombies

Friday, January 29th, 2010

Motivation: Zombies

Motivation: Procrastination

Thursday, January 28th, 2010


Motivation: Intimidation…

Wednesday, January 27th, 2010


Motivation: Brute Force

Tuesday, January 26th, 2010

Motivation: Brute Force


Monday, January 25th, 2010

… is awesome, isn’t it…


If only lldp worked on the opposite sex (or using lldp to work out which switches you’re plugged into)

Sunday, January 24th, 2010

Have you ever had to ask “where does this cable go”? If so, you will probably want to read on.

lldp (or Link Layer Discovery Protocol) is a vendor-neutral Data Link Layer protocol used by network devices for advertising of their identity, capabilities, and interconnections.

I hacked up a quick set of scripts last night that report back to a central database the status of every interface on a server, including:

  • hostname
  • interface name
  • port status
  • switch name
  • switch port
  • port speed

These simple, hacky, scripts will allow you to get an overview of your servers’ uplinks and easily identify mis-patches and cabling faults.


  • Ever interface has to be up for this to work (up, but does not necessarily need an IP) (ifconfig -a | grep eth | awk {‘print $1′} | while read line; do ifconfig $line up; done)
  • You must have lldpd running on your server
  • Your switch must support lldp and this must be enabled. This can be enabled on a foundry system by:
    lldp enable ports all
    lldp run


`id` bigint(20) NOT NULL auto_increment,
`timestamp` bigint(20) default NULL,
`hostname` char(255) default NULL,
`interface` char(5) default NULL,
`status` char(5) default NULL,
`switch` char(100) default NULL,
`port` int(11) default NULL,
`speed` char(255) default NULL,
`mac` char(64) default NULL,
PRIMARY KEY  (`id`),
KEY `myIndex` (`hostname`,`interface`)) ;


$parameters = array(

mysql_connect('localhost', "root", "");

$keys = '';
$value = '';

foreach ($parameters as $v) {
$keys .= ",$v ";
$value .= ", '".mysql_real_escape_string($_GET[$v])."'";

$query = "INSERT INTO `data` (timestamp $keys) VALUES (".date('U')." $value);";


source /etc/profile

ifconfig -a | grep eth | while read line ; do
ETH=$(echo $line | awk {'print $1'})
SWITCH=$(lldpctl $ETH | grep SysName | awk {'print $2'}) ;
PORT=$(lldpctl $ETH | grep PortDescr | awk {'print $2'} | awk -v'FS=/' {'print $3'}) ;
MAC=$(echo $line | awk {'print $5'});
HOSTNAME=$(hostname | awk -v"FS=." {'print $1'})
LINK=$(ethtool $ETH | grep "Link detected" | awk {'print $3'})
SPEED=$(lldpctl $ETH  | grep "MAU oper type" | cut -c 19-)


wget -o /dev/null -O/dev/null $URL


You can then easily get a list of your interfaces and statuses by running:

mysql interfaces -e "select * from data where id in 
    (select max(id) from data group by hostname, interface);"

These scripts were written in a hurry to solve an annoying problem, there is no guarantee that they will work for you, and no assurance that the data they produce will be accurate. They shouldn’t (but could) harm your system and are almost certainly painfully slow and inefficient. :-)

Deleting old keys from known_hosts

Monday, January 18th, 2010

A quick snippet of bash to remove a specific line from your known_hosts.


if [ ! -z "$1" ] ; then
        echo "Call me with a line number as a parameter"

cat > /tmp/scriptin.removeknownhosts << EOF

vim ~/.ssh/known_hosts +$line -s /tmp/scriptin.removeknownhosts

rm -f /tmp/scriptin.removeknownhosts