]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/hex2ip.pl
* New hex2ip module
[infobot.git] / src / Modules / hex2ip.pl
1 #
2 #  hex2ip.pl: Convert hex gateway idents to an IP (eg:ABCDEF12)
3 #     Author: Dan McGrath <djmcgrath@users.sourceforget.net>
4 #  Licensing: Artistic License (as perl itself)
5 #    Version: v0.1
6 #
7 #  Copyright (c) 2007 Dan McGrath
8 #
9
10 package hex2ip;
11
12 use strict;
13
14 sub hex2ip::convert {
15     my $hexstr = shift;
16     my $result;
17
18     &::VERB("hex2ip: Converting Hex address $hexstr to IP");
19
20     if ( $hexstr =~ /^([a-fA-F0-9]{2}){4}$/ ) {
21         my @conv;
22         $hexstr =~ /(..)(..)(..)(..)/;
23
24         push @conv, hex($1);
25         push @conv, hex($2);
26         push @conv, hex($3);
27         push @conv, hex($4);
28
29         $result = uc "$hexstr = " . join(".", @conv);
30     } else {
31         $result = "Invalid string: $hexstr";
32     }
33
34         return($result);
35 }
36
37 sub hex2ip::query {
38         &::performStrictReply(&convert(@_));
39         return;
40 }
41
42 1;
43
44 # vim:ts=4:sw=4:expandtab:tw=80