Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 30 lines (24 sloc) 647 Bytes
#!/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
}