Skip to content

Instantly share code, notes, and snippets.

@YouSysAdmin
Last active October 30, 2015 07:37
Show Gist options
  • Save YouSysAdmin/181d2dd3291ce707c8cc to your computer and use it in GitHub Desktop.
Save YouSysAdmin/181d2dd3291ce707c8cc to your computer and use it in GitHub Desktop.
Async network scanner
#!/usr/bin/env ruby
# gem install celluloid net-ping
require 'celluloid/current'
require 'net/ping'
require 'ipaddr'
class ScanPort
include Celluloid
def scan host, port
res = Net::Ping::TCP.new(host, port)
if res.ping?
type = detect(res.host)
puts "[+] #{host} : #{type}\n"
end
end
def detect(ip)
begin
data = Net::HTTP.get_response(ip, '/')
if !data.body.empty?
response = data.body
else
response = data.header['set-cookie']
end
case response
when /LuCI/
'OpenWRT LuCI'
when /mikrotik/
'MikroTik'
when /AIROS_/
'Ubiquiti'
when /DVR Components/
'eDVR'
when /ITV/
'ITV WebServer Client'
when /It works!/
'Blank NGINX'
when /m.jsp/
'Phantom DWDR'
when /DVR IE Video/
'DVR IE Video - model?'
when />TL-(.*)</
"TP-Link #{$1}"
when /doc\/page\/login.asp/, /\/index.asp">location<\/a>./
'HikVision DVR'
when />WEB SERVICE</
'Maybe - Dahua DVR'
else
'Not detect'
end
rescue
'Response error'
end
end
end
def make_hosts_list(network)
ip_range = IPAddr.new network
(ip_range.to_range).map(&:to_s)
end
def main network, port
hosts = make_hosts_list(network)
hosts.each do |host|
sc = ScanPort.new
sc.async.scan host, port
end
end
if ARGV.size < 2
puts "USE: #{File.basename(__FILE__)} network port "
puts "Sample: #{File.basename(__FILE__)} 192.168.0.1/24 80 "
exit
end
main ARGV[0], ARGV[1].to_i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment