Google Answers Logo
View Question
 
Q: Perl; Sockets. ( No Answer,   4 Comments )
Question  
Subject: Perl; Sockets.
Category: Computers > Programming
Asked by: modena-ga
List Price: $185.00
Posted: 08 Dec 2004 04:16 PST
Expires: 07 Jan 2005 04:16 PST
Question ID: 439745
I want a script i have modified slightly, so i can use it with
password protected sites as well..
the code atm is:
$socket = IO::Socket::INET->new( Proto => "tcp", PeerAddr =>
"$server", PeerPort => "8080") || die "[-] Unable to connect";
which works fine if the site isnt password protected.. ie http://test.com
now, suppose i want to access a site, test.com, with the user: test and pass: test2
http://test:test2@test.com doesnt work.

How do i modify it so it works for the second option as well?
Just give me the code :).

need a quick answer.

Regards.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Perl; Sockets.
From: pne-ga on 09 Dec 2004 07:38 PST
 
IO::Socket sounds like doing things the hard way... is there a reason
why you're not using LWP::Simple or LWP::UserAgent, which will handle
the HTTP request for you rather than making you speak HTTP yourself? I
tried using the http://user:password@example.com/ method using
LWP::Simple::getprint and got the result I expected (i.e. LWP handled
the authentication for me).

If you do not want to or cannot change the program in this manner,
you'll have to do the HTTP authentication yourself. I presume the site
you wish to connect to uses HTTP Basic authentication, which is
described in RFC 2617 (available from
ftp://ftp.isi.edu/in-notes/rfc2617.txt, among other places). This
basically involves sending an HTTP header "Authorization: Basic
XXXXXX" with the XXXXXX replaced by the Base-64 encoding of the string
formed by username + ":" + pasword. (For example, user "test" and
password "test2" would result in an HTTP header "Authorization: Basic
dGVzdDp0ZXN0Mg==" since "dGVzdDp0ZXN0Mg==" is the Base-64 encoded
version of "test:test2".)

Base-64 encoding is specified in section 6.8 of RFC 2045, though if
possible, I'd use the Perl MIME::Base64 module rather than reinventing
the wheel and rolling my own code.

So something like

  my $credentials = encode_base64("test:test2");
  print $socket "Authorization: Basic $credentials\015\012";

somewhere in the middle of sending the HTTP headers (for example,
after the header "GET / HTTP/1.0" is sent).
Subject: Re: Perl; Sockets.
From: pne-ga on 15 Dec 2004 21:12 PST
 
Has the previous comment been helpful?

If not, you may wish to supply more information (such as which Perl
modules you have available and whether you can install others) and/or
more code (specifically, around the part where HTTP headers are sent).
Subject: Do you still have a problem?
From: pne-ga on 05 Jan 2005 02:31 PST
 
Do you still have questions or problems? This request will expire soon.
Subject: Re: Perl; Sockets.
From: samb0-ga on 05 Jan 2005 06:20 PST
 
Their may be an easier way of doing what you want. Are you stuck with
PERL or can you use another language, either way it's pretty easy to
do. I have a script in 3 different languages that logs onto a website
and run manual task such as typing information and click on submit
button to gather data and then put data into SQL database.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy