metalx1000

BASH Port Scanner

May 4th, 2020
2,862
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###poor man's port scanner###
  2. #must support /dev/tcp -- use BASH
  3. #check port
  4. echo > /dev/tcp/127.0.0.1/8 && echo "Port is open" ||echo "Port is closed"
  5.  
  6. #avoid errors on closed ports
  7. (echo > /dev/tcp/127.0.0.1/8) 2> /dev/null && echo "Port is open" ||echo "Port is closed"
  8.  
  9. #scan many ports
  10. for i in {20..10000};
  11. do
  12.   (echo > /dev/tcp/127.0.0.1/$i) &>/dev/null &&
  13.   echo "Port $i is open";
  14. done
  15.  
  16. #as oneliner
  17. for i in {20..10000};do (echo > /dev/tcp/127.0.0.1/$i) &>/dev/null && echo "Port $i is open";done
RAW Paste Data