I see no reason for this, other than your web solution is trying to write > echo “I’m sorry “$USER”, you must be root to run this script.” Permanent output files with timestamps in their name so that multipleĪttempts do not overwrite old data unnecessarily. Check out the mktemp command toĮasily find/use temporary files for output. Why hard-coded to /root instead of elsewhere? Also, losing old data when > # Note: This script has to be run with root permissions to get full benefit > # A simple port scanner performed on ‘localhost’ I think openSUSE actually lets you use eitherĭepending on which netcat package you’ve installed. Note that on some distributions the command ‘nc’ is For instance, it would be nice to know what is using those Also, if anyone has a way to improve it that would > script works, I am absolutely certain there are mistakes or better ways > compare the two, but in my final script, it will be gone. > left the web solution included in the script should someone want to > information and runs a lot faster and uses way less CPU resources. > this be better?” Turns out it is, if only for the fact it provides more Then I happened upon ‘netcat’ and thought “could > was actually just the command, so I embellished it a bit to include > and came across a web post on how to scan ‘localhost’ for open ports. > So I was thinking about what I could try next in my quest to learn bash Note: entrys with a '*' I added, not the programĪs always, comments, suggestions, corrections and such are appreciated. # Lets us know script is done by sending us a beep.Īnd here is the output file: = Report Generated Sunday J12:41:42 EDTĬonnection to localhost 25 port succeeded!Ĭonnection to localhost 7634 port succeeded!Ĭonnection to localhost 55453 port succeeded!Ĭonnection to localhost 60924 port succeeded! Nc -vz localhost $myRange1-$myRange2 2>&1 |grep succeeded Nc -vz localhost $myRange1-$myRange2 2>&1 | grep succeeded | tee > $myFile # Note: on my default system I have the 'netcat-openbsd' package. # ++++++++++ TIME TO SCAN PORTS ++++++++++Įcho -e "Scanning for open ports using web solutionįor (( p=$myRange1 p/dev/tcp/localhost/$p) >/dev/null 2>&1 & echo "$p open" | tee > $myFile įor (( p=$myRange1 p/dev/tcp/localhost/$p) >/dev/null 2>&1 & echo "$p open" Įcho -e "Scanning for open ports using netcat (nc) If "$myRange2" -lt "$myRange1"+1 ]] || "$myRange2" -gt "65535" ]]Įcho "Must be greater than Range 1 and less than or equal to 65535" Read -p "Enter the ending port you want to check ]: " myRange2 Read -p "Enter the first port you want to check ]: " myRange1 Read -p "Enter the port you want to check : " myRange1 Read -s -n1 -p "Moving on, do you want to check a (s)ingle port or a (r)ange of ports : " myOpt # ++++++++++ GET PORT OR PORT RANGE ++++++++++Įcho "Ports are generally divided into three groups:"Įcho "**** Well Known Ports: 0-1023" # I am omitting '0' from this range and making 1 the minimum portĮcho -e "**** Dynamic/Private Ports: 49152-65535 *) # Presses something other than 'y' or 'n' Y|Y) # see if file /root/port_scanner.txt exists, If no, then create, if yes, move onĮcho "= Report Generated "$myDate > $myFileĮcho -e "++++++ File /root/open_ports.txt ready.Įcho -e "++++++ No file will be created or modified Read -s -n1 -p "Do you want to save data to a file : " myAns # Note: This script has to be run with root permissions to get full benefitĮcho "I'm sorry "$USER", you must be root to run this script."Įcho -e "Hello, "$USER". # A simple port scanner performed on 'localhost' For instance, it would be nice to know what is using those open ports. Also, if anyone has a way to improve it that would be great. Though the script works, I am absolutely certain there are mistakes or better ways of doing what I did. I’ve left the web solution included in the script should someone want to compare the two, but in my final script, it will be gone. Then I happened upon ‘netcat’ and thought “could this be better?” Turns out it is, if only for the fact it provides more information and runs a lot faster and uses way less CPU resources. It was actually just the command, so I embellished it a bit to include options, printing, etc. So I was thinking about what I could try next in my quest to learn bash and came across a web post on how to scan ‘localhost’ for open ports.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |