initial commit
[old-and-random.git] / upnp / upnp.pl
1 #!/usr/bin/perl
2
3 use Net::UPnP::ControlPoint;
4
5 my $obj = Net::UPnP::ControlPoint->new();
6
7 @dev_list = $obj->search(st =>'upnp:rootdevice', mx => 3);
8
9 $devNum= 0;
10 foreach $dev (@dev_list) {
11     $device_type = $dev->getdevicetype();
12     if  ($device_type ne 'urn:schemas-upnp-org:device:MediaServer:1') {
13         next;
14     }
15     print "[$devNum] : " . $dev->getfriendlyname() . "\n";
16     unless ($dev->getservicebyname('urn:schemas-upnp-org:service:ContentDirectory:1')) {
17         next;
18     }
19     $condir_service = $dev->getservicebyname('urn:schemas-upnp-org:service:ContentDirectory:1');
20     unless (defined(condir_service)) {
21         next;
22     }
23     %action_in_arg = (
24             'ObjectID' => 0,
25             'BrowseFlag' => 'BrowseDirectChildren',
26             'Filter' => '*',
27             'StartingIndex' => 0,
28             'RequestedCount' => 0,
29             'SortCriteria' => '',
30         );
31     $action_res = $condir_service->postcontrol('Browse', \%action_in_arg);
32     unless ($action_res->getstatuscode() == 200) {
33             next;
34     }
35     $actrion_out_arg = $action_res->getargumentlist();
36     unless ($actrion_out_arg->{'Result'}) {
37         next;
38     }
39     $result = $actrion_out_arg->{'Result'};
40     while ($result =~ m/<dc:title>(.*?)<\/dc:title>/sgi) {
41         print "\t$1\n";
42     }
43     $devNum++;
44 }