From 2a383d8fa8eeb44c1f40dc4fe49e8de486c8ea82 Mon Sep 17 00:00:00 2001 From: djmcgrath Date: Sat, 1 Dec 2007 01:20:08 +0000 Subject: [PATCH] * New hex2ip module git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@1631 c11ca15a-4712-0410-83d8-924469b57eb5 --- doc/USAGE | 3 +++ files/infobot.help | 4 ++++ src/CommandStubs.pl | 1 + src/Modules/hex2ip.pl | 44 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 src/Modules/hex2ip.pl diff --git a/doc/USAGE b/doc/USAGE index 9dac0a3..23786fe 100644 --- a/doc/USAGE +++ b/doc/USAGE @@ -16,6 +16,9 @@ for list of configuration options, run: ===== + infobot: hex2ip aaBBcD12 + me: AABBCD12 = 170.187.205.18 + infobot: test is testing me: okay infobot: testing? diff --git a/files/infobot.help b/files/infobot.help index c44576d..c0370ee 100644 --- a/files/infobot.help +++ b/files/infobot.help @@ -490,4 +490,8 @@ rssfeeds: E: rssfeeds flush rssfeeds: D: flush - Will erase the cache file. (Must be chattr +o) rssfeeds: D: update - Force a manual update of the feeds. (Must be chattr +o) +hex2ip: D: Convert Hex idents for some gateways to an IP address +hex2ip: U: ## <8 char hex value> +hex2ip: E: ## AabBcC12 + # vim:ts=4:sw=4:expandtab:tw=80 diff --git a/src/CommandStubs.pl b/src/CommandStubs.pl index 7df2c73..95878b1 100644 --- a/src/CommandStubs.pl +++ b/src/CommandStubs.pl @@ -763,6 +763,7 @@ sub nullski { &addCmdHook('factinfo', ('CODEREF' => 'factinfo', 'Cmdstats' => 'Factoid Info', Module => 'Factoids', ) ); &addCmdHook('factstats?', ('CODEREF' => 'factstats', 'Cmdstats' => 'Factoid Stats', Help => 'factstats', Forker => 1, 'Identifier' => 'Factoids', ) ); &addCmdHook('help', ('CODEREF' => 'help', 'Cmdstats' => 'Help', ) ); +&addCmdHook('hex2ip', ('CODEREF' => 'hex2ip::query', 'Forker' => 1, 'Identifier' => 'hex2ip', 'Cmdstats' => 'hex2ip', 'Help' => 'hex2ip') ); &addCmdHook('HTTPDtype', ('CODEREF' => 'HTTPDtype::HTTPDtype', 'Identifier' => 'HTTPDtype', 'Cmdstats' => 'HTTPDtype', 'Forker' => 1) ); &addCmdHook('[ia]?spell', ('CODEREF' => 'spell::query', 'Identifier' => 'spell', 'Cmdstats' => 'spell', 'Forker' => 1, 'Help' => 'spell') ); &addCmdHook('insult', ('CODEREF' => 'Insult::Insult', 'Forker' => 1, 'Identifier' => 'insult', 'Help' => 'insult' ) ); diff --git a/src/Modules/hex2ip.pl b/src/Modules/hex2ip.pl new file mode 100644 index 0000000..6ac4585 --- /dev/null +++ b/src/Modules/hex2ip.pl @@ -0,0 +1,44 @@ +# +# hex2ip.pl: Convert hex gateway idents to an IP (eg:ABCDEF12) +# Author: Dan McGrath +# Licensing: Artistic License (as perl itself) +# Version: v0.1 +# +# Copyright (c) 2007 Dan McGrath +# + +package hex2ip; + +use strict; + +sub hex2ip::convert { + my $hexstr = shift; + my $result; + + &::VERB("hex2ip: Converting Hex address $hexstr to IP"); + + if ( $hexstr =~ /^([a-fA-F0-9]{2}){4}$/ ) { + my @conv; + $hexstr =~ /(..)(..)(..)(..)/; + + push @conv, hex($1); + push @conv, hex($2); + push @conv, hex($3); + push @conv, hex($4); + + $result = uc "$hexstr = " . join(".", @conv); + } else { + $result = "Invalid string: $hexstr"; + } + + return($result); +} + +sub hex2ip::query { + &::performStrictReply(&convert(@_)); + return; +} + +1; + +# vim:ts=4:sw=4:expandtab:tw=80 -- 2.39.2