Skip to content

Instantly share code, notes, and snippets.

@pahnin
Created September 5, 2012 15:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pahnin/3638098 to your computer and use it in GitHub Desktop.
Save pahnin/3638098 to your computer and use it in GitHub Desktop.
Dc hub scanner for LAN
#This Script is released under Gnu GPL
require 'socket'
require 'timeout'
class Hubscan
def initialize
@init_ip=192
@end_ip=216
@verbose=false
@time_out=10
puts "Do you want to continue with default configuration? Press n to enter custom settings [Y/n]"
self.get_choice do |x|
if x =~ /^[yY]/ then
self.print_settings
self.scan
else
puts "Enter start ip range as in xxx in 192.168.xxx.0\n"
@init_ip=gets.chop.to_i
puts "Enter start ip range as in xxx in 192.168.xxx.255\n"
@end_ip=gets.chop.to_i
puts "Enable verbose mode? Verbose mode enables you to see whats happening in detail throught the scannig process [Y/n]"
self.get_choice do |x|
if x=~ /^[yY]/ then
@verbose=true
end
end
puts "Enter the maximum time for each scan, ideally between 10 to 100"
@time_out=gets.chop.to_i
self.print_settings
self.scan
end
end
end
def print_settings
puts "Scan Settings:\nFrom:192.168.#{@init_ip}.0\tTo:192.168.#{@end_ip}.255\nVerbose Mode?: #{@verbose}\tTime span for each scan: #{@time_out}"
end
def get_choice
while @choice=gets.chop and !/^[yYnN]/.match(@choice) do
puts "Please enter one of the following y/Y/n/N"
end
yield @choice
end
class Hubrunning < Exception
end
def scan
puts "-----------Starting Scan--------------"
(@init_ip..@end_ip).each do |i|
(0..255).each do |j|
print "Scannig 192.168.#{i}.#{j}\t" if @verbose
begin
time_limit=Timeout::timeout(@time_out/1000.0) {
@sock=TCPSocket.new("192.168.#{i}.#{j}",411)
raise Hubrunning, "Hub found"
}
rescue Hubrunning
begin
puts "DC hub found at => 192.168.#{i}.#{j}"
ensure
@sock.close
end
rescue Errno::ENOBUFS
puts "Sorry! Ran out of memory!"
rescue Timeout::Error
puts "Error: Timeout" if @verbose
rescue Errno::ENETUNREACH
puts "Error: Network not reachable" if @verbose
rescue Errno::ECONNREFUSED
puts "Error: Connection refused" if @verbose
end
end
end
puts "-----------End of Scan----------------\nClose your DC++ and run for best results\nDo you want to run the scan again? [Y/n]"
self.get_choice do |x|
if x =~ /^[yY]/ then
self.scan
else
puts "Credits: Phanindra Srungavarapu\nEmail: pahninsd@gmail.com\nSource code: https://gist.github.com/3638098"
end
end
end
end
Hubscan.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment