You are not logged in.

#1 2017-12-17 16:39:08

amaro
Member
From: xfce
Registered: 2014-05-09
Posts: 367

[SOLVED] whois script - fgets: Connection reset by peer

Hey guys!

I am using a script to check for free domain names. I got it from 'linuxconfig.org'. It's named 'domain'.

cat /usr/local/bin/domain
#!/bin/bash

# Name: Check for domain name availability
# linuxconfig.org
# Please copy, share, redistribute and improve

if [ "$#" == "0" ]; then
    echo "You need to supply at least one argument!"
    exit 1
fi

DOMAINS=( '.com' '.net' '.info' \
'.org' '.pro' )

ELEMENTS=${#DOMAINS[@]}

while (( "$#" )); do

  for (( i=0;i<$ELEMENTS;i++)); do
      whois $1${DOMAINS[${i}]} | egrep -q \
      '^No match|^NOT FOUND'
      if [ $? -eq 0 ]; then
          echo "$1${DOMAINS[${i}]} : available"
      fi
  done

shift

done

It was working till the last time I used it. Now it gives

domain gooogl
fgets: Connection reset by peer
gooogl.net : available
gooogl.pro : available

What could be the most possible reason for that?

Last edited by amaro (2017-12-17 17:12:41)

Offline

#2 2017-12-17 16:55:06

null
Member
Registered: 2009-05-06
Posts: 398

Re: [SOLVED] whois script - fgets: Connection reset by peer

No idea what all those bashism do, but this script is way to large for what it does.

#!/usr/bin/bash
for domain in com net info org pro; do
    if ! whois ${1}.$domain >> /dev/null; then
        echo "${1}.$domain available"
    fi
done

does the same and works fine for me. It seems that whois sets the return code to 1 if it can't find the domain, but you allways can add your grep for "No match" or whatever..

Also I somtimes get the "fgets: Connection reset by peer" error randomly. And whois servers usually only allow a certain amount of queries per time.

Offline

#3 2017-12-17 17:12:16

amaro
Member
From: xfce
Registered: 2014-05-09
Posts: 367

Re: [SOLVED] whois script - fgets: Connection reset by peer

I tested your script and got no error.
Thank you, null!

Offline

Board footer

Powered by FluxBB