Connecting Tech Pros Worldwide Help | Site Map

Question on opening a Socket

Newbie
 
Join Date: Jun 2007
Posts: 25
#1: Oct 17 '07
Hi,
I am working as a software test engineer(testing docsis compliant devices like cable modem). I have done Perl programming involving hashes, files, regex and modules. But right now, I have to automate a task which involves opening a socket. (which I have not done before)

Here is the problem:-

From my Linux server, I have to open a connection to another windows PC which is on the same network.
After getting to that PC, I have to open a web page http://192.168.100.1 (which is the diagnostic web page for the modem) It will ask for authentication. I have to enter my username and password.
After going to that web page there is an option called backup. Basically I have to click that and upload the file that I have in my script.

This is my question:-
Is it possible in Perl or should I use someother language?
Any tips or suggestions on how to approach this problem?

I would apreciate your response.

Thanks,
san
eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 900
#2: Oct 18 '07

re: Question on opening a Socket


Not experienced in this category. Sorry -:(

A good start would possibly be perlipc. Another good place would be to look at CPAN. All else fails try Google.
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#3: Oct 18 '07

re: Question on opening a Socket


Perl comes with IO::Socket which seems like a logical place to start.
Newbie
 
Join Date: Oct 2007
Posts: 7
#4: Oct 18 '07

re: Question on opening a Socket


Hi,

Following code is an easy code to start with sockets. This code opens a socket connection with a HTTP server and gets back a file from it.

Expand|Select|Wrap|Line Numbers
  1. # -----------------------------------------------------
  2. use IO::Socket;
  3.  
  4.     $host = "www.google.com" ;
  5.     $document = "/index.html" ; 
  6.     $BLANK = "\n\n\n" ;
  7.  
  8.         $remote = IO::Socket::INET->new( Proto     => "tcp",
  9.                                          PeerAddr  => $host,
  10.                                          PeerPort  => "http(80)",
  11.                                         );
  12.         unless ($remote) { die "cannot connect to http daemon on $host" }
  13.         print "Socket object created\n" ;
  14.         $remote->autoflush(1);
  15.         print "Autoflush done\n" ;
  16.         print $remote "GET $document HTTP/1.0"  . $BLANK;
  17.         print "Request written\n" ;
  18.         while ( <$remote> ) { print }
  19.         close $remote;
  20. # -------------------------------------------------------------
  21.  
the username/password thing you mentioned, need to be worked out. But this can be a starter.

Regards
Reply