Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…

#!/usr/bin/env perl | |
# martin, 2018-12-20 | |
# ... fetches external IPv4 address using DuckDuckGo | |
use strict; | |
use warnings; | |
use utf8; | |
use Mojo::UserAgent; | |
sub DDG { 'https://duckduckgo.com/?q=my+ip&t=h_&ia=answer' } | |
sub strip_tags { $_[0] =~ s/<.[^>]*>//gr } | |
my ($pure); | |
for (@ARGV) { | |
if (/--?p(ure)?/) { $pure++ } | |
else { print "usage: $0 [--pure]\n"; exit } | |
} | |
my $html = Mojo::UserAgent->new->get(DDG)->result->body; | |
if ($html =~ m@Your IP address is (?<info>(?<ip>.*?) in .*?</a>)@) { | |
if ($pure) { | |
print $+{ip}, "\n"; | |
} else { | |
print strip_tags($+{info}), "\n"; | |
} | |
} else { | |
print "Segmentation fault (core dumped)\n"; # HEH | |
} |