-2

I'm trying to connect to a server and earn the banner, but I'm not succeeding.

My script runs in theory as follows:

  1. Get port and IP but I can use port e IP static on variables.

  2. Execute the socket, with timeout 7

  3. If connected

  4. Wait the response e use the handle <> to get banner

  5. Execute print to show banner.

use IO::Socket::INET

$myip = <stdin>;     # $myip is the remote IP to connect
chomp($myip);
$myport = <stdin>;   # $myport is the remote port to connect 
chomp($myport);

# This part of data entry tends to use IP and URL frames, but it doesn't work either.
$sock=IO::Socket::INET‐>new("$myip:$myport");

if($sock){
    $remote=IO::Socket::INET‐>new(
        Proto=>"tcp",
        PeerAddr=>$myip,
        PeerPort=>$myport,
        Timeout=>"7"
    );
    $line=<$remote>;
    print $line;
}

When I run the code, the connection is executed, but I don't gain banner. I cannot find an error in this code. I looked for a solution on other websites, but I couldn't find it. It's always the same examples and they don't change.

TLP
  • 66,756
  • 10
  • 92
  • 149
  • 3
    1. Add `use strict; use warnings` to your program. 2. Fix the errors that appear. 3. If the problem persists, ask again. – TLP Jun 11 '21 at 16:28
  • @TLP, I add strict and warning. The result is Unrecognized character \xE2; marked by <-- HERE after cket::INET<-- HERE near – Gilmar Trevizan Jun 11 '21 at 16:52
  • You are missing a semi-colon after the first line. Fix that. The `\xE2` looks like you are using the wrong character for the dash in the arrow. It should be `->`, nothing else. – TLP Jun 11 '21 at 16:56
  • @TLP fixed, but still not receiving banner. My script keeps waiting to get the response with the banner. What is your opinion? – Gilmar Trevizan Jun 11 '21 at 17:09
  • I don't see an `accept` function call. – mob Jun 11 '21 at 17:21
  • @mob. How is it? – Gilmar Trevizan Jun 11 '21 at 17:28
  • 1
    Why are you opening two connections to the remote computer? – Shawn Jun 11 '21 at 21:04
  • @GilmarTrevizan I am not familiar with this module. But I do notice that you use the constructor twice, and the first time you use no timeout, so maybe the program is just waiting indefinitely for a response. – TLP Jun 11 '21 at 23:02
  • @TLP I used the script for get banner of other services like FTP, SSH, SMTP and it works, but not get banner for the web. I think use User Agent for get banner web. – Gilmar Trevizan Jun 12 '21 at 00:08
  • @Shawn for test. – Gilmar Trevizan Jun 12 '21 at 00:08

1 Answers1

0

http protocol expects a request from a client before it sends any reply.

Try the following code snippet with ip address of your http server.

#!/usr/bin/env perl
#
# vim: ai ts=4 sw=4

use strict;
use warnings;

use IO::Socket::INET;

my $ip   = '192.186.1.120';
my $port = '80';

my $sock = IO::Socket::INET->new("$ip:$port");

print $sock "GET / HTTP/1.0\n\n";

print while <$sock>;

Reference: HTTP flow

Polar Bear
  • 6,762
  • 1
  • 5
  • 12