mercredi 23 novembre 2016

Stop script if nc connetion succeded in bash

How can I stop my script if the connection with netcat was successful? For example if Connection to 192.168.2.4 21 port [tcp/ftp] succeeded! I'm not sure what holds that string of text.

#!/bin/bash

#Find first 3 octets of the gateway and set it to a variable.

GW=$(route -n | grep 'UG[ \t]' | awk '{print $2}' | cut -c1-10)

#loop through 1 to 255 on the 4th octect 
for octet4 in {1..255}
do
        sleep .2
        nc -w1 $GW$octet4 21

done

Aucun commentaire:

Enregistrer un commentaire