File: decode.pl

package info (click to toggle)
cgiirc 0.5.9-3squeeze1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 896 kB
  • ctags: 443
  • sloc: perl: 9,125; ansic: 163; sh: 99; makefile: 43
file content (30 lines) | stat: -rw-r--r-- 810 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/perl
# (C) 2000 David Leadbeater (http://contact.dgl.cx/)
# cgi-irc comes with ABSOLUTELY NO WARRANTY
# This is free software, and you are welcome to redistribute it
# under certain conditions; read the file COPYING for details

# Decode hex ip addresses as found in CGI:IRC whois (realname) output with the 
# encode ip addresses option turned on

# Now i understand wtf pack and unpack do:
# perl -le'print join ".", unpack "C*",pack "H*", $ARGV[0]'

use strict;
use Socket;
my($input,$output);

if($#ARGV >= $[) {
	$input = shift;
} else {
	print "Type the Hex IP to decode into a normal IP address\n";
	$input=<>;
}

$input =~ s/[^a-z0-9]//gi;

$output = pack "H*", $input;

print "IP: " . join(".", unpack "C*", $output) . "\n";
print "Host: " . scalar gethostbyaddr($output, AF_INET) . "\n";