-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathx-net-my-external-ip
executable file
·57 lines (45 loc) · 1.67 KB
/
x-net-my-external-ip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env perl
#
# Use UPnP to find out your own IP address if behind a NAT device
#
# Pedro Melo <[email protected]>
#
use strict;
use warnings;
use Net::UPnP::ControlPoint;
use Net::UPnP::GW::Gateway;
my $obj = Net::UPnP::ControlPoint->new();
my @dev_list = $obj->search(st =>'upnp:rootdevice', mx => 3);
my $devNum= 0;
foreach my $dev (@dev_list) {
my $device_type = $dev->getdevicetype();
print " >> device type $device_type\n";
next unless $device_type eq 'urn:schemas-upnp-org:device:InternetGatewayDevice:1';
my $name = $dev->getfriendlyname() || '<unamed>';
print " >> name $name\n";
next unless $dev->getservicebyname('urn:schemas-upnp-org:service:WANIPConnection:1');
my $gwdev = Net::UPnP::GW::Gateway->new;
$gwdev->setdevice($dev);
print "\tExternalIPAddress = " . $gwdev->getexternalipaddress() . "\n";
print "[$devNum]: $name\n";
next unless $dev->getservicebyname('urn:schemas-upnp-org:service:ContentDirectory:1');
my $condir_service = $dev->getservicebyname('urn:schemas-upnp-org:service:ContentDirectory:1');
next unless defined($condir_service);
my %action_in_arg = (
'ObjectID' => 0,
'BrowseFlag' => 'BrowseDirectChildren',
'Filter' => '*',
'StartingIndex' => 0,
'RequestedCount' => 0,
'SortCriteria' => '',
);
my $action_res = $condir_service->postcontrol('Browse', \%action_in_arg);
next unless $action_res->getstatuscode() == 200;
my $actrion_out_arg = $action_res->getargumentlist();
next unless $actrion_out_arg->{'Result'};
my $result = $actrion_out_arg->{'Result'};
while ($result =~ m/<dc:title>(.*?)<\/dc:title>/sgi) {
print "\t$1\n";
}
$devNum++;
}