File: decode.pl

package info (click to toggle)
cgiirc 0.5.4-6sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 916 kB
  • ctags: 424
  • sloc: perl: 8,904; sh: 821; ansic: 132; makefile: 54
file content (25 lines) | stat: -rw-r--r-- 751 bytes parent folder | download
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
#!/usr/bin/perl
# (C) 2000 David Leadbeater (cgiirc@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);

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";