Wednesday, September 15, 2010

My Favorite netcat(nc) combinations

Netcat(nc) has always been referred to as the legendary Swiss Army Knife of Networking. It is a single binary, which takes up about some KB of space of space on your disk, but yet so handy!! Below are some of my netcat favorite I use time to time.

See which ports are open on a particular server.

#nc -v -w 2 -z 172.16.80.70 1-65535

Checking disk status of a set of server mentioned in a text file wslist.txt


#for i in `cat wslist.txt`; do echo $i; ssh -q $i df -h|grep /data$|awk '{ if($5>=90) {print $5 "->Disk Danger"} else { print "Disk OK"}}' ; done

Check if port 22 is open a list of server mentioned in wslist.txt

#for i in `cat wslist.txt`; do nc -v -w 1 -z $i 22 ; done

Transfer a file from Server A to Server B on a specified port.

Server B
nc -l 1337 > dk.txt

Server A
nc 172.16.80.70 1337 <>

[rick@TestBox ~]# nc -l 1337
Hey Debu,did you know we can chat on the console like this?
@Rick, yeah! It's so cool man..


[debu@c00000005221 ~]$ nc 172.16.80.70 1337

Hey Debu,did you know we can chat on the console like this?
@Rick, yeah! It's so cool man..


Ctrl+d


Network Scan:


range="172.16.80."; port=80; for host in $(seq 1 255); do multi_task=$(result=$(nc -zv $range$host $port 2>&1 | grep succeeded); if [ -n "$result" ]; then echo $range$host":"$port >> "/tmp/pscan"; fi;) & done



Cheers!

DK

No comments:

Post a Comment

RCA - Root Cause Analysis

An important step in finding the root causes of issues or occurrences that happen within a system or organization is root cause analysis (RC...