Commit b4134cc8 authored by rygelgit's avatar rygelgit

Added modules to search for UPnP devices, filter devices that have diage...

Added modules to search for UPnP devices, filter devices that have diage capability, build a list of devices, IP, port. Also updated the README.md with the packages to install. Now the DIAGC.pl script has two options: To search network devices for diage or a manual way to input host IP and Port to test a particular device.
parent 3e2c815c
......@@ -36,13 +36,62 @@ use utils::Util;
use utils::SocketCalls;
use include::ActionRequestInclude;
use include::ActionResponseInclude;
use include::UPnPInclude;
use responsevalidator::ResponseValidator;
our ($TEST_OPTION, $HOSTIP, $HOSTPORT) = '';
print "------- Choose an option -------\n";
print "1. Search DIAGE capable devices \n";
print "2. Manual DIAGE device testing \n";
print "3. Enter x to exit \n";
print "Enter the option number : ";
our $SEARCH_OPTS = <>;
chomp $SEARCH_OPTS;
switch($SEARCH_OPTS){
case 1 {
my ($diage_devices, $diage_ip, $diage_port) = SearchDevices::lookup_diage_device;
print "Choose the corresponding device number to start testing: :\n";
my $diage_dev_count=0;
print "****************************************\n";
print "****************************************\n";
foreach my $diage_temp (@$diage_devices) {
print "----------------------------------------\n";
print "[" . ($diage_dev_count + 1) . "] : " . $diage_temp->getfriendlyname() . "\n";
print "Device IP : " . @$diage_ip[$diage_dev_count] . "\n";
print "Device Port : " . @$diage_port[$diage_dev_count] . "\n";
$diage_dev_count++;
}
print "****************************************\n";
print "****************************************\n";
print "Choose the device number: ";
my $DEVICE_NO = <>;
chomp $DEVICE_NO;
$HOSTIP = @$diage_ip[$DEVICE_NO - 1];
$HOSTPORT = @$diage_port[$DEVICE_NO - 1];
Util::print_diagc_start;
}
case 2 {
Util::print_diagc_start;
}
case ('x') {
exit;
}
else { exit;}
}
while (1) {
Util::print_diagc_start;
our ($OPTION, $HOSTIP, $HOSTPORT) = Util::get_user_input;
$TEST_OPTION = Util::get_user_options;
if ($SEARCH_OPTS eq '2') {
($HOSTIP, $HOSTPORT) = Util::get_manual_device_details;
}
switch($OPTION){
switch($TEST_OPTION){
case 1 {
my $devicestatus_response = DeviceStatusRequest::devicestatus_request($HOSTIP, $HOSTPORT);
ResponseValidator::valiate_soap_response($devicestatus_response);
......@@ -112,6 +161,9 @@ our ($OPTION, $HOSTIP, $HOSTPORT) = Util::get_user_input;
ResponseValidator::valiate_soap_response($traceroute_res_response);
}
case ('x') { exit; }
else { exit; }
}
Util::print_diagc_start;
}
1;
Install Switch module before using the script:
----------------------------------------------
sudo apt-get install libswitch-perl
sudo apt-get install libnet-upnp-perl
Running the script:
-------------------
......
#!/bin/usr/perl
# Copyright (c) 2014, CableLabs, Inc.
# All rights reserved.
#
......@@ -25,7 +27,7 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#!/bin/usr/perl
package ActionRequestInclude;
use requestaction::DeviceStatusRequest;
use requestaction::CancelTestRequest;
......
#!/usr/bin/perl
# Copyright (c) 2014, CableLabs, Inc.
# All rights reserved.
#
# Author: Parthiban Balasubramanian<p.balasubramanian@cablelabs.com>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
package UPnPInclude;
use utils::SearchDevices;
1;
......@@ -44,3 +44,5 @@ our $ping_response_message2="</TestID>
sub ping_response {
return SocketCalls::invoke_soap_request($_[0], $_[1], $ping_response_message1 . $_[2] . $ping_response_message2, $ping_response_action);
}
1;
#!/usr/bin/perl
# Copyright (c) 2014, CableLabs, Inc.
# All rights reserved.
#
# Author: Parthiban Balasubramanian<p.balasubramanian@cablelabs.com>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
use strict;
use utils::SearchDevices;
SearchDevices::lookup_diage_device;
1;
#!/usr/bin/perl
# Copyright (c) 2014, CableLabs, Inc.
# All rights reserved.
#
# Author: Parthiban Balasubramanian<p.balasubramanian@cablelabs.com>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
package SearchDevices;
use utils::UPnPWrapper;
use Net::UPnP::Device;
use Net::UPnP::ControlPoint;
sub search_devices {
my ($devices, $ip, $port) = UPnPWrapper::search();
print "Total Devices found on network : " .@$devices . "\n";
return ($devices, $ip, $port);
}
sub lookup_diage_device {
my ($device_list_search, $device_ip_list, $device_port_list) = search_devices;
$devNum= 0;
my (@temp_device_list, @temp_device_ip, @temp_device_port)= ();
foreach my $dev_temp (@$device_list_search) {
unless ($dev_temp->getservicebyname('urn:schemas-upnp-org:service:BasicManagement:2')) {
$devNum++;
next;
}
push (@temp_device_list , $dev_temp);
push (@temp_device_ip, @$device_ip_list[$devNum]);
push (@temp_device_port, @$device_port_list[$devNum]);
# print "[" . ($devNum + 1) . "] : " . $dev_temp->getfriendlyname() . "\n";
# print "Device IP : " . @$device_ip_list[$devNum] . "\n";
# print "Device Port : " . @$device_port_list[$devNum] . "\n";
$devNum++;
}
print "Devices with DIAGE capability: " . @temp_device_list . "\n";
return (\@temp_device_list, \@temp_device_ip, \@temp_device_port);
}
1;
#!/usr/bin/perl
package UPnPWrapper;
use strict;
use Socket;
use Net::UPnP;
use Net::UPnP::HTTP;
use Net::UPnP::Device;
sub search {
my $ssdp_header = "M-SEARCH * HTTP/1.1\r\n
ST: upnp:rootdevice\r\n
Man: \"ssdp:discover\"\r\n
MX: 5\r\n
Host: $Net::UPnP::SSDP_ADDR:$Net::UPnP::SSDP_PORT\r\n\r\n";
print "******************** SSDP Message ********************\n";
print $ssdp_header;
print "******************** SSDP Message ********************\n";
socket(SSDP_SOCK, AF_INET, SOCK_DGRAM, getprotobyname('udp'));
my $ssdp_multicast_msg = sockaddr_in($Net::UPnP::SSDP_PORT, inet_aton($Net::UPnP::SSDP_ADDR));
send(SSDP_SOCK, $ssdp_header, 0, $ssdp_multicast_msg);
my @device_list=();
my @device_addr=();
my @device_port=();
my ($reader_input, $reader_output, $ssdp_res_msg) = '';
vec($reader_input, fileno(SSDP_SOCK), 1) = 1;
while( select($reader_output = $reader_input, undef, undef, 10) ) {
recv(SSDP_SOCK, $ssdp_response, 4096, 0);
print $ssdp_response . "\n";
unless ($ssdp_response =~ m/LOCATION[ :]+(.*)\r/i) {
next;
}
my $location = $1;
unless ($location =~ m/http:\/\/([0-9a-z.]+)[:]*([0-9]*)\/(.*)/i) {
next;
}
my $host_address = $1;
my $host_port = $2;
my $dev_path = '/' . $3;
my $http_request = Net::UPnP::HTTP->new();
my $post_response = $http_request->post($host_address, $host_port, "GET", $dev_path, "", "");
my $post_content = $post_response->getcontent();
my $dev = Net::UPnP::Device->new();
$dev->setssdp($ssdp_response);
$dev->setdescription($post_content);
push(@device_list, $dev);
push(@device_addr,$host_address);
push(@device_port,$host_port);
}
close(SSDP_SOCK);
# Multiple arrays cannot be passed by value., If passed then all the values will be dumped into the first array
# So return the array references. And also use my qualifier, so that a new instance will be created where it is assigned.
return (\@device_list, \@device_addr, \@device_port);
}
1;
......@@ -48,13 +48,14 @@ sub print_diagc_start {
print " ---------------------\n";
}
sub get_user_input {
sub get_user_options {
print "Input the number corresponding to the action to be invoked : ";
our $USR_OPT = <>;
chomp $USR_OPT;
if ($USR_OPT eq 'x') {
return ($USR_OPT);
}
return $USR_OPT;
}
sub get_manual_device_details {
print "Enter the DIAGE host IPAddress : " ;
our $IP = <>;
chomp $IP;
......@@ -62,7 +63,7 @@ sub get_user_input {
our $PORT = <>;
chomp $PORT;
print "\n";
return ($USR_OPT, $IP, $PORT);
return ($IP, $PORT);
}
1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment