I recently finished a Port Scanner project written in Ruby. What this does is it asks what site (or ip) you want to scan, that is, if you are online. If you are offline, the scanner will, obviously, not work. It will also scan on local area network IP addresses. The program utilizes the 'ping' library's pingecho() method located in the Ping class. The pingecho() takes the following arguments in the following order: Ping.pingecho(site/ip, timout (in seconds), port). The method acts like a normal ping program and scans on a site on a certain port number with a timeout specified in seconds. I have made a fairly simple to understand program that does this in a fairly simple way. Please email me any changes you may want me to make in the program, and that shall be done. The log file that the program creates will be stored in the same directory as the program (*.rb). Enjoy!
PS Please remember to include the correct shebang at the beginning of the file and have Ruby installed. If you don't know what to use for the shebang, please look at my about page to find out.
A screenshot of the program in action are below...
[img]http://connor.myvnc.com/Screenshot.png[/img]
#----Written by Phore (aka thedavinci)----#
#----Require the libraries----#
require 'ping'
#----Define the current port number being scanned----#
cport=0
#----Get the user input information----#
puts "Site to scan (no www, http, etc):\n"
site=gets
puts "Start port:"
startp=gets
puts "End port:"
endp=gets
puts "Timeout (seconds):"
timeout=gets
#----Chomp the newline riddled strings----#
startp=startp.chomp
endp=endp.chomp
site=site.chomp
timeout=timeout.chomp
#----Define the current port number as the starting port number----#
cport=startp.to_i
#----Tell the user that the scanner is scanning----#
puts "--Scanning--\n"
#----Start the port scanner----#
if (startp.to_i >= 0 && endp.to_i <= 65535)
#----Open the log file (saved in the same directory as the ruby file)----#
log=File.new("portlog.txt", "w")
#----The beginning of the log file----#
log.puts "--Port Scan Log of site #{site} on ports "+"#{startp}"+"-#{endp} with a timeout of "+"#{timeout}"+" second(s)--\n"
log.puts "--Log of scan is as follows--\n"
while (cport >= startp.to_i && cport <= endp.to_i)
torf=Ping.pingecho("#{site.chomp}", timeout.to_i, cport.to_i)
if (torf==true)
puts "Scanning on port #{cport}....\033[31mTRUE\033[0m"
log.puts "Scanning on port #{cport}....**TRUE**"
else
puts "Scanning on port #{cport}....false"
end
cport += 1
end
#----Notify the user that the process completed----#
puts "--Port scanner complete--\n"
puts "--Press enter to exit--\n"
log.close
gets
else
puts "--Please choose valid port numbers--\n--Press enter to exit--\n"
gets
end
PS Please remember to include the correct shebang at the beginning of the file and have Ruby installed. If you don't know what to use for the shebang, please look at my about page to find out.
A screenshot of the program in action are below...
[img]http://connor.myvnc.com/Screenshot.png[/img]
0 Comments On This Entry
← February 2022 →
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 |
Tags
My Blog Links
Recent Entries
-
Port Scanner written in Rubyon Mar 21 2009 08:45 PM
Search My Blog
1 user(s) viewing
1 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)



Leave Comment








|