473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Regular expressions using IO::Socket

60
Expand|Select|Wrap|Line Numbers
  1. use IO::Socket;
  2.  
  3. my $path= "http://website.com/aaa.php";
  4.  
  5. print q(
  6.    __________
  7. -/* Script v1.0 *\-
  8.    ------------------
  9. );
  10.  
  11. print q(
  12. Link: );
  13. $postit = <STDIN>;
  14. chop($postit);
  15.  
  16. $len = legth $postit;
  17.  
  18. sub get_link() {
  19.     $postit = shift;
  20.     $len = shift;
  21.     $path = shift;
  22.     my $sock = new IO::Socket::INET(
  23.         PeerAddr => "host.net",
  24.         PeerPort => "80",
  25.         Proto    => "tcp",
  26.     );
  27.     die "ERROR";
  28.  
  29.     print $sock "POST $path HTTP/1.1\n";
  30.     print $sock "Host: $hosting\n";
  31.     print $sock "Accept: */*\n";
  32.     print $sock "Referer: $path\n";
  33.     print $sock "Accept-Language: en-us\n";
  34.     print $sock "Content-Type: application/x-www-form-urlencoded\n";
  35.     print $sock "User-Agent: SOME_UA\n";
  36.     print $sock "Connection: Keep-Alive\n";
  37.     print $sock "Length: $len\n";
  38.     print $sock "Content: $postit\n";
  39.     close($sock);
  40.  
  41.     $socket =~ /URL (.*) \(Hello there\) found at (.*)</body>/;
  42.     @y = ($1, $2);
  43.     return @y;
  44.     echo "OK";
  45. }
  46.  
  47. echo get_link($postit, $len, $path);
Is the regexp ok ?
And what about the script, should that do what is supposed to, echo the stuff that the regexp gets ??
Sep 3 '07 #1
4 1657
miller
1,089 Expert 1GB
Is the regexp ok ?
And what about the script, should that do what is supposed to, echo the stuff that the regexp gets ??
Your script is missing "use strict;". This is the biggest problem with it, and is the cause of your primary bug.

On a secondary note, I suggest that you use LWP for getting webpages, instead of IO::Socket

- Miller
Sep 3 '07 #2
pplers
60
yeah, but doesn't it matter that i use POST and not GET ??
Sep 3 '07 #3
numberwhun
3,509 Expert Mod 2GB
yeah, but doesn't it matter that i use POST and not GET ??
I agree with Miller. If all you are trying to do is fetch a web page, then you can do so easier with LWP. Take a read on the link he provided.

Regards,

Jeff
Sep 3 '07 #4
pplers
60
Thanks i already had a web, now the script works great.

But i want to finish it by using a file downloader with some sort of progress bar (text mode) in perl.... Does anyone got experience in this subject ?
Sep 3 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Rad | last post by:
Im trying to lauch a small perl program in cygwin which listens for arguments on a specified port. When executing this line (18) ; my $sock = new IO::Socket::INET(LocalPort => $DAEMONPORT,...
1
by: Dan Kelley | last post by:
I have 2 projects - 1 Winform project that sends Udp messages using the UdpClient class when a button is clicked, and a Console application that listens for these Udp messages. If I try to use...
1
by: Kueishiong Tu | last post by:
How do I send and receive internet messages using socket in the .net VC++ environment? Coding sample will be helpful.
2
by: Alpha | last post by:
Hi, I'm able to make connection to a server using socket connection. However, when I send a command string the server just ignores it. All command string needs to start with "0xF9" at Byte 0. ...
8
by: kardon33 | last post by:
Currently i am working on a project to send a UDP packet through the ArtNet protocol and receive a message back and read and output it. right now i can send the message fine and the device i send it...
1
by: kardon33 | last post by:
How would i receive an incoming UDP packet in perl with IO::SOCKET::INET???
1
by: Dimbeswar Pathak | last post by:
I got an error message "use" not allowed in expression at client.pl line 2, at end of line syntax error at client.pl line 2, near "use IO::Socket::INET" Execution of client.pl aborted due to...
2
by: cookspyder | last post by:
In reference to streaming data over socket: Any one know how to keep a IO socket open while sending data everytime my while loops runs and collects data the connection closes and while the loop...
0
by: Nyoka | last post by:
Hi All, I am trying to great a webserver that works over https (443) and listens on a single ip address on a machine that has multiple ip addresses. use IO::Socket::SSL; $socket = new...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.