2014-10-28 11:34:36 -07:00
|
|
|
package DDG::Goodie::Teredo;
|
|
|
|
# ABSTRACT: Provides the Teredo server IPv4 address,
|
|
|
|
# NAT IPv4 address, and port number encoded in a given
|
|
|
|
# Teredo tunnel IPv6 address.
|
|
|
|
|
2015-02-22 12:09:29 -08:00
|
|
|
use strict;
|
2014-10-28 11:34:36 -07:00
|
|
|
use DDG::Goodie;
|
|
|
|
use Net::IP;
|
|
|
|
use Math::BaseConvert;
|
|
|
|
|
|
|
|
triggers start => 'teredo';
|
|
|
|
|
|
|
|
primary_example_queries 'teredo 2001:0000:4136:e378:8000:63bf:3fff:fdd2';
|
|
|
|
description 'Teredo address analyzer';
|
|
|
|
name 'Teredo extractor';
|
|
|
|
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Teredo.pm';
|
|
|
|
topics 'sysadmin';
|
|
|
|
category 'transformations';
|
2015-01-07 10:24:47 -08:00
|
|
|
attribution github => ['seanheaton','Sean Heaton'],
|
|
|
|
twitter => ['seanograph','Sean Heaton'],
|
2015-12-29 06:03:50 -08:00
|
|
|
email => ['seanoftime@gmail.com','seanoftime@gmail.com'],
|
|
|
|
github => ["https://github.com/Mailkov", "Melchiorre Alastra"];
|
2014-10-28 11:34:36 -07:00
|
|
|
|
|
|
|
zci answer_type => 'teredo';
|
|
|
|
zci is_cached => 1;
|
|
|
|
|
2015-12-29 06:09:42 -08:00
|
|
|
# Params: server, port, client
|
|
|
|
sub to_text {
|
2015-12-29 09:08:58 -08:00
|
|
|
return "Teredo Server IPv4: " . $_[0] . "\nNAT Public IPv4: " . $_[2]
|
|
|
|
. "\nClient Port: " . $_[1];
|
2015-12-29 06:09:42 -08:00
|
|
|
}
|
|
|
|
|
2014-10-28 11:34:36 -07:00
|
|
|
handle remainder => sub {
|
|
|
|
my @output = ();
|
2014-10-28 11:36:15 -07:00
|
|
|
|
2014-10-28 11:34:36 -07:00
|
|
|
# Create an IPv6 address from the query value
|
|
|
|
my $ip = new Net::IP ($_,6) if $_;
|
|
|
|
|
|
|
|
# Verify the query value is a valid Teredo IPv6 address
|
|
|
|
if ((defined $ip) && ($ip->version() == 6) && (substr($ip->ip(),0,9) eq "2001:0000")) {
|
2015-12-29 09:07:10 -08:00
|
|
|
my $binip = $ip->binip();
|
2014-10-28 11:36:15 -07:00
|
|
|
|
2015-12-29 09:07:10 -08:00
|
|
|
# bits 32 to 64 designate IPv4 address of the Teredo server used
|
|
|
|
my $netip = new Net::IP (Net::IP::ip_bintoip((substr $binip, 32, 32),4));
|
2015-12-29 08:41:36 -08:00
|
|
|
my $teredo = $netip->ip();
|
2015-12-29 09:07:10 -08:00
|
|
|
push @output, $teredo;
|
2014-10-28 11:34:36 -07:00
|
|
|
|
2015-12-29 09:07:10 -08:00
|
|
|
# negation of bits 80 to 96, converted to decimal, designate NAT port number
|
|
|
|
my $port = (65535 - cnv((substr $binip, 80, 16),2,10));
|
|
|
|
push @output, $port;
|
2014-10-28 11:34:36 -07:00
|
|
|
|
2015-12-29 09:07:10 -08:00
|
|
|
# negation of bits 96 to 128 designate IPv4 address of NAT device
|
|
|
|
$netip = new Net::IP (Net::IP::ip_bintoip(~(substr $binip, 96, 32),4));
|
2015-12-29 08:41:36 -08:00
|
|
|
my $nat = $netip->ip();
|
2015-12-29 09:07:10 -08:00
|
|
|
push @output, $netip->ip();
|
2015-12-29 08:41:36 -08:00
|
|
|
|
|
|
|
my %output = (
|
|
|
|
'Teredo Server IPv4:' => $teredo,
|
|
|
|
'Nat Public IPv4:' => $nat,
|
|
|
|
'Client Port:' => $port,
|
|
|
|
);
|
|
|
|
|
2015-12-29 09:07:10 -08:00
|
|
|
return to_text(@output),
|
2015-12-29 08:41:36 -08:00
|
|
|
structured_answer => {
|
|
|
|
id => 'teredo',
|
|
|
|
name => 'Answer',
|
|
|
|
data => {
|
|
|
|
record_data => \%output,
|
|
|
|
record_keys => ['Teredo Server IPv4:', 'Nat Public IPv4:', 'Client Port:'],
|
|
|
|
},
|
|
|
|
templates => {
|
|
|
|
group => 'list',
|
|
|
|
options => {
|
|
|
|
content => 'record',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-10-28 11:34:36 -07:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
1;
|