Test multiple IP:Port servers

Hello,

I am pretty unskilled in bash and I need some script and my skills ale limited (yet) I am learning but situation now needs some more skills.

is there possibility to simply check IP address with ports from csv file?

My csv has hundred of IPs in this format

123.123.321.321:80,22,443
223.223.321.321:80,22,443

Is there possibility to check IPs in this order and format via bash script to make it automatic?

Can shell script take care of commas in that csv? In best way I want that telnet test output in some tetxt file with format

IP:PORT - FAIL/OK

.. is that possible?

Thank you alot in advance

How about

awk -F: '{for (i=split ($2, T, ","); i>0; i--) print "nc -zv ", $1, T}' file | sh
nc: connect to 10.1.1.11 port 80 (tcp) failed: Connection refused
Connection to 10.1.1.11 22 port [tcp/ssh] succeeded!
nc: connect to 10.1.1.11 port 21 (tcp) failed: Connection refused

I copied youd script and it gives me

111.222.333.444.555: inverse host lookup failed: Host name lookup failure 
(UNKNOW)  [111.222.333.444.555] 22 (ssh) open

I don't understand to that Inverse host lookup failed..

With that IP address I understand that message well. It has several errors. Use well structured IP addresses only.

Thats just example I wont expose my IPs publicly :slight_smile: This error was on normal IP address.

DNS resolution seems to fail, which may well be if we're dealing with e.g. an unregistered host on the LAN. Other reasons are possible as well. Still, that looks like an informative message; the test itself seems to have worked...

Yes, the main functions works, thank you alot .. :slight_smile:

And can I setup output like

awk -F: '{for (i=split ($2, T, ","); i>0; i--) print "nc -zv ", $1, T}' file | sh > output.txt

?

Try adding an n to the nc options to avoid name resolution.

Also one more question .. is this solution also for IP ranges? Just curious question..

nc can do that - give it a try.