-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathx-net-upnp-browser
executable file
·52 lines (43 loc) · 1.4 KB
/
x-net-upnp-browser
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
#!/usr/bin/env perl
#
# Scan the Network for UPnP devices
#
# Pedro Melo <[email protected]>
#
use strict;
use warnings;
use Net::UPnP::ControlPoint;
# $Net::UPnP::DEBUG++;
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();
my $name = $dev->getfriendlyname();
if ($device_type ne 'urn:schemas-upnp-org:device:MediaServer:1') {
$name ||= '<unamed>';
print "Device type '$device_type' named '$name', ignored\n";
next;
}
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++;
}