This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 942
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #917 from duckduckgo/mintsoft/iplookup
IPLookup: First rough version based on RobTex's API
- Loading branch information
Showing
6 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package DDG::Spice::IPLookup; | ||
# ABSTRACT: Returns information about an IP address | ||
|
||
use DDG::Spice; | ||
use Regexp::IPv6 qw($IPv6_re); | ||
|
||
primary_example_queries "reverse dns 8.8.8.8"; | ||
description "Shows reverse DNS information about an IP"; | ||
name "IPLookup"; | ||
category 'computing_tools'; | ||
topics "sysadmin"; | ||
|
||
attribution github => ['https://github.com/mintsoft', 'mintsoft'], | ||
web => 'http://www.robtex.com/'; | ||
|
||
triggers startend => 'ip lookup', 'iplookup', 'reverse dns', 'reverse ip', 'dns', 'whois'; | ||
|
||
spice to => 'https://www.robtex.com/ext/xapiq/?q=$1&filter=none&s=wip,asip,ddg&r=json'; | ||
spice wrap_jsonp_callback => 1; | ||
|
||
sub is_ipv4($) | ||
{ | ||
my ($ip) = @_; | ||
return undef unless $ip =~ /^([0-9]{1,3}\.){3}([0-9]{1,3})$/; | ||
my @octlets = split /\./, $ip; | ||
for (@octlets) { | ||
return undef if int($_) > 255 || int($_) < 0; | ||
} | ||
return 1; | ||
} | ||
|
||
handle remainder => sub { | ||
s/for|of|lookup//; | ||
s/\s//; | ||
return $_ if (is_ipv4($_) || /^$IPv6_re$/); | ||
return; | ||
}; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div> | ||
{{#each famlist from="0" to="1"}} | ||
<h1 class='text--primary iplookup_domain_name zci__header--detail'><a href='http://{{this}}'>{{this}}</a></h1> | ||
{{/each}} | ||
<div class='text--primary iplookup_owner'>Owner: {{shortwho}}</div> | ||
<div class='text--secondary iplookup_location'>{{shortloc}}</div> | ||
{{#if blacklists}} | ||
<div class='text--secondary iplookup_blacklist'>Blacklists: | ||
<ul class='blacklists text--secondary'> | ||
{{#each blacklists}} | ||
<li>{{this}}</li> | ||
{{/each}} | ||
</ul> | ||
</div> | ||
{{/if}} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
ul.blacklists | ||
{ | ||
margin: 0; | ||
padding: 0; | ||
padding-top: 0.2em; | ||
} | ||
|
||
.zci h1.iplookup_domain_name | ||
{ | ||
font-size: 1.5em; | ||
font-weight: 500; | ||
margin-bottom: 0; | ||
} | ||
|
||
.iplookup_owner | ||
{ | ||
font-size: 1.3em; | ||
font-weight: 300; | ||
} | ||
|
||
.zci__more-at--info img | ||
{ | ||
padding-right: 0.4em; | ||
} | ||
|
||
.iplookup_blacklist | ||
{ | ||
margin-top: 0.5em; | ||
} | ||
|
||
.iplookup_location, .iplookup_blacklist | ||
{ | ||
margin-bottom: 0.5em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(function (env) { | ||
"use strict"; | ||
env.ddg_spice_iplookup = function(api_result){ | ||
|
||
if (!api_result || api_result.error) { | ||
return Spice.failed('iplookup'); | ||
} | ||
|
||
Spice.add({ | ||
id: "iplookup", | ||
name: "Answer", | ||
data: api_result.ddg, | ||
meta: { | ||
sourceName: "RobTex", | ||
sourceUrl: api_result.ddg.lnk | ||
}, | ||
templates: { | ||
group: 'info', | ||
options: { | ||
content: Spice.iplookup.content | ||
} | ||
}, | ||
relevancy: { | ||
primary: [{ | ||
required: 'shortwho' | ||
}] | ||
} | ||
}); | ||
}; | ||
}(this)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use DDG::Test::Spice; | ||
|
||
ddg_spice_test( | ||
[qw( DDG::Spice::IPLookup )], | ||
'reverse dns 8.8.8.8' => test_spice( | ||
'/js/spice/iplookup/8.8.8.8', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::IPLookup', | ||
), | ||
'reverse dns for 1.2.3.4' => test_spice( | ||
'/js/spice/iplookup/1.2.3.4', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::IPLookup', | ||
), | ||
'reverse dns of 1.2.3.4' => test_spice( | ||
'/js/spice/iplookup/1.2.3.4', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::IPLookup', | ||
), | ||
'reverse dns lookup 1.2.3.4' => test_spice( | ||
'/js/spice/iplookup/1.2.3.4', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::IPLookup', | ||
), | ||
'dns of 1.2.3.4' => test_spice( | ||
'/js/spice/iplookup/1.2.3.4', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::IPLookup', | ||
), | ||
'reverse ip lookup 1.2.3.4' => test_spice( | ||
'/js/spice/iplookup/1.2.3.4', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::IPLookup', | ||
), | ||
'dns 10.20.30.40' => test_spice( | ||
'/js/spice/iplookup/10.20.30.40', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::IPLookup', | ||
), | ||
'whois 1.2.3.4' => test_spice( | ||
'/js/spice/iplookup/1.2.3.4', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::IPLookup', | ||
), | ||
'reverse dns 256.8.8.8' => undef, | ||
'reverse dns a.b.c.d' => undef, | ||
'reverse dns duckduckgo.com' => undef, | ||
'reverse dns for a.b.c.d' => undef, | ||
'reverse dns for 2607:f0d0:1002:0051:0000:0000:0000:0004' => test_spice( | ||
'/js/spice/iplookup/2607%3Af0d0%3A1002%3A0051%3A0000%3A0000%3A0000%3A0004', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::IPLookup', | ||
), | ||
'ip lookup for 5.6.7.8' => test_spice( | ||
'/js/spice/iplookup/5.6.7.8', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::IPLookup' | ||
), | ||
'reverse dns for fe80::200:f8ff:fe21:67cf' => test_spice( | ||
'/js/spice/iplookup/fe80%3A%3A200%3Af8ff%3Afe21%3A67cf', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::IPLookup', | ||
), | ||
); | ||
|
||
done_testing; | ||
|