2

i made a script that uses a socket to get an info from a whois server. All is ok, but when i pass any of .online tld's domain response from whois.nic.online is: DOMAIN NOT FOUND!. But when i use command "whois -h whois.nic.online example.online" in the terminal(Linux) i get all info that i needed. Please tell me what is the problem with the WHOIS.NIC.ONLINE?

use strict;
use warnings;
use IO::Socket;

if (scalar @ARGV == 0 or $ARGV[0] =~ /^[\d]{1, 20}/) {

  print "There is no parameter\n";
  exit();

}

my $domain_name = $ARGV[0];
my $query_resp_server_socket = new IO::Socket::INET(
  PeerAddr => 'whois.iana.org',
  PeerPort => 43,
  Proto => 'tcp');

print {$query_resp_server_socket} "$domain_name\n";
print $query_resp_server_socket "\r\n";
my @answer_from_iana = <$query_resp_server_socket>;
close($query_resp_server_socket);

my $responsive_whois_server;

foreach (@answer_from_iana) {

  if(/whois\.[a-zA-Z0-9-]{2, 20}\.[a-zA-Z0-9-]{2, 20}$/) {
    if ($& eq "whois.nic.online") {
      $responsive_whois_server = "whois.nic.online";
    }
    else {
      $responsive_whois_server = $&;
    }
  }

}

my $query_data_socket = new IO::Socket::INET(
  PeerAddr => $responsive_whois_server,
  PeerPort => 43,
  Proto => 'tcp');

print {$query_data_socket} "$domain_name\n";
print $query_data_socket "\r\n";

my @answer_from_resp_server = <$query_data_socket>;
close($query_data_socket);

if ( scalar @ARGV == 1 ) {

  print @answer_from_resp_server;

}
elsif( scalar @ARGV == 2 and $ARGV[1] eq "-exp" ) {

  foreach (@answer_from_resp_server) {

    if (/paid-till|Registry Expiry Date/) {

      print $_;

    }
    else {

      print "Info was not found."

    }

  }

}
elsif( scalar @ARGV == 2 and $ARGV[1] eq "-stat" ) {

  foreach (@answer_from_resp_server) {

    if (/state|Domain Status/) {

      print $_;

    }
    else {

      print "Info was not found."

    }

  }

}
elsif ( scalar @ARGV == 2 and $ARGV[1] eq "-adm" ) {

  foreach (@answer_from_resp_server) {

    if (/person|Registrant Organization/) {

      print $_;

    }
    else {

      print "Info was not found."

    }

  }

}
user508828
  • 41
  • 2
  • 1
    Try this: `print {$query_data_socket} "$domain_name\r\n";` – Erwin Jul 03 '22 at 22:16
  • There are some other aspects of the script that need some work, but I believe that's the key issue. – Erwin Jul 03 '22 at 22:18
  • @Erwin To use print() wouldn't you need to enable flush? Other wise the data sits in a buffer. It would make more sense to use the send function from IO::Socket. – FractalLotus Jul 04 '22 at 00:11
  • 1
    My main point was to change `\n` to `\r\n`. The buffer will be flushed. Did you actually test it? There’s certainly a fair number of things I’d do different as well, if I were asked to write this code, but I thought that was beside the point. – Erwin Jul 04 '22 at 00:31
  • Thanks guys, for answers, i'll try all of it and i'll get you know if one of these works – user508828 Jul 04 '22 at 19:07
  • @Erwin, would you recommend turn all of this stuff into OOP? – user508828 Jul 04 '22 at 19:14
  • 1
    @user508828 - It could be a useful (practice) exercise. Aside from that I see little benefit from doing that for _this_ script. My thoughts were more along the lines of proper option parsing `use getopt` and (as @FractalLotus suggested) using appropriate `IO::Socket` methods, putting common code in a function, etc. – Erwin Jul 05 '22 at 19:33

0 Answers0