| 1 | use Net::UPnP::ControlPoint;
|
|---|
| 2 | use Net::UPnP::Device;
|
|---|
| 3 | use URI::URL;
|
|---|
| 4 | require LWP::UserAgent;
|
|---|
| 5 | require XML::LibXML;
|
|---|
| 6 |
|
|---|
| 7 | my $obj = Net::UPnP::ControlPoint->new();
|
|---|
| 8 |
|
|---|
| 9 | @dev_list = $obj->search(st =>'upnp:rootdevice', mx => 3);
|
|---|
| 10 |
|
|---|
| 11 | $devNum= 0;
|
|---|
| 12 | foreach $dev (@dev_list) {
|
|---|
| 13 | print "\n### Device ###";
|
|---|
| 14 | $device_type = $dev->getdevicetype();
|
|---|
| 15 | print "\n $device_type\n\n ";
|
|---|
| 16 | # if ($device_type ne 'urn:schemas-upnp-org:device:MediaServer:1') {
|
|---|
| 17 | # next;
|
|---|
| 18 | # }
|
|---|
| 19 | print "[$devNum] : " . $dev->getfriendlyname() . "\n";
|
|---|
| 20 | print "\n Manufactor ".$dev->getmanufacturer();
|
|---|
| 21 | print "\n manufacturer_url ".$dev->getmanufacturerurl();
|
|---|
| 22 | print "\n model_description ".$dev->getmodeldescription();
|
|---|
| 23 | print "\n model_name ".$dev->getmodelname();
|
|---|
| 24 | print "\n model_number ".$dev->getmodelnumber();
|
|---|
| 25 | print "\n model_url ".$dev->getmodelurl();
|
|---|
| 26 | print "\n serialnumber ".$dev->getserialnumber();
|
|---|
| 27 | print "\n udn ".$dev->getudn();
|
|---|
| 28 | print "\n upc ".$dev->getupc();
|
|---|
| 29 |
|
|---|
| 30 | my $url = URI->new( $dev->getlocation() );
|
|---|
| 31 | print "\n service_list ".$dev->getservicelist();
|
|---|
| 32 | @service_list =$dev->getservicelist();
|
|---|
| 33 |
|
|---|
| 34 | print "\n##############################\n";
|
|---|
| 35 |
|
|---|
| 36 | foreach my $service (@service_list) {
|
|---|
| 37 | $serviceID=$service->getserviceid();
|
|---|
| 38 | $servDesc=$service->getdevicedescription(name=>'SCPDURL' );
|
|---|
| 39 | # print "\n ID=".$serviceID."\nDesc ".$servDesc." type ".$service->getservicetype()."\n";
|
|---|
| 40 |
|
|---|
| 41 | # $url->path( $servDesc );
|
|---|
| 42 |
|
|---|
| 43 | my $ua = LWP::UserAgent->new;
|
|---|
| 44 | $ua->timeout(10);
|
|---|
| 45 | $ua->env_proxy;
|
|---|
| 46 |
|
|---|
| 47 | my $response = $ua->get($url);
|
|---|
| 48 |
|
|---|
| 49 | if ($response->is_success) {
|
|---|
| 50 | print "\n ####################";
|
|---|
| 51 | print $response->decoded_content;
|
|---|
| 52 | print "\n #####################";
|
|---|
| 53 | my $parser = XML::LibXML->new();
|
|---|
| 54 |
|
|---|
| 55 | my $doc = $parser->parse_string( $response->decoded_content );
|
|---|
| 56 | my $root = $doc->firstChild();
|
|---|
| 57 |
|
|---|
| 58 | my $xpc = XML::LibXML::XPathContext->new( $root );
|
|---|
| 59 | $xpc->registerNs('x', 'urn:schemas-upnp-org:service-1-0');
|
|---|
| 60 | my @xactions = $xpc->findnodes('//x:actionList/x:action/x:name' );
|
|---|
| 61 | foreach my $action (@xactions) {
|
|---|
| 62 | @result=(@result, $action->textContent());
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | print "\n UPNP decode";
|
|---|
| 66 | foreach my $action ( @actions ) {
|
|---|
| 67 | $_ = $action;
|
|---|
| 68 | print "\nActions =".$actions;
|
|---|
| 69 |
|
|---|
| 70 | # post all 'Get' actions
|
|---|
| 71 | if ( /^Get/ ) {
|
|---|
| 72 | my %action_in_arg = ();
|
|---|
| 73 | my $action_res = $service->postaction( $action, \%action_in_arg);
|
|---|
| 74 | if ($action_res->getstatuscode() == 200) {
|
|---|
| 75 | my $arg_ref = $action_res->getargumentlist();
|
|---|
| 76 | my %args = %$arg_ref;
|
|---|
| 77 | foreach my $k ( keys %args ) {
|
|---|
| 78 | print "" . $serviceID . "::" . $action . ":" . $k . " = " . $args{$k} . "\n";
|
|---|
| 79 | }
|
|---|
| 80 | }
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | else {
|
|---|
| 90 | die $response->status_line;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|