Keagan
March 30, 2017, 4:44am
1
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
RudiC
March 30, 2017, 7:23am
2
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
Keagan
March 30, 2017, 7:39am
3
rudic:
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..
RudiC
March 30, 2017, 7:43am
4
With that IP address I understand that message well. It has several errors. Use well structured IP addresses only.
Keagan
March 30, 2017, 7:46am
5
Thats just example I wont expose my IPs publicly This error was on normal IP address.
RudiC
March 30, 2017, 7:52am
6
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...
Keagan
March 30, 2017, 7:55am
7
rudic:
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 ..
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
?
RudiC
March 30, 2017, 7:56am
8
Try adding an n
to the nc
options to avoid name resolution.
Keagan
March 30, 2017, 7:59am
9
Also one more question .. is this solution also for IP ranges? Just curious question..
RudiC
March 30, 2017, 8:03am
10
nc
can do that - give it a try.