snmpscan 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +62 -0
  2. data/bin/snmpscan +157 -0
  3. metadata +54 -0
data/README ADDED
@@ -0,0 +1,62 @@
1
+ *SYNOPSIS*
2
+
3
+ Snmpscan is a simple, yet powerful (and fast!) command-line SNMP
4
+ scanner. Its aim is to reproduce the funcionalities of popular tools
5
+ such as nbtscan, scanssh, smtpscan and other.
6
+
7
+
8
+ *WEB REFERENCES*
9
+
10
+ Home page: http://snmpscan.rubyforge.org/
11
+ Project page (and download): http://rubyforge.org/projects/snmpscan/
12
+
13
+
14
+ *REQUISITIES*
15
+
16
+ You must have Ruby installed (of course!) and the wonderful SNMP Ruby
17
+ library written by Dave Halliday (http://snmplib.rubyforge.org/).
18
+ Download a copy from http://rubyforge.org/projects/snmplib/ or simply
19
+ do a
20
+
21
+ # gem install snmp
22
+
23
+
24
+ *INSTALLATION*
25
+
26
+ If you got this software on a tarball tgz, simply install it with
27
+
28
+ # ruby setup.rb
29
+
30
+ Otherwise you can use gem:
31
+
32
+ # gem install snmpscan
33
+
34
+
35
+ *EXAMPLES*
36
+
37
+ Directly from the online help:
38
+
39
+ snmpscan 10.10.10.64
40
+ Scans host 10.10.10.64 with default values
41
+
42
+ snmpscan -t 200 -c comread -m sysName 172.30.149.0/24
43
+ Scans a range of 255 addresses for mib sysName.0, with comunity
44
+ password "comread" and a timeout value of 200 milliseconds
45
+
46
+ If you use the -V (--verbose) option, you will have more output, like
47
+ a string with the motivation for the failed scan for every host:
48
+
49
+ snmpscan -V 172.30.149.0/24
50
+
51
+ 172.30.149.0: host 172.30.149.0 not responding
52
+ 172.30.149.1: host 172.30.149.0 not responding
53
+
54
+ and so on.
55
+
56
+
57
+ *AUTHOR and LICENSE*
58
+
59
+ This software is written by Marco Ceresa.
60
+ ceresa@gmail.com
61
+
62
+ License: Ruby.
@@ -0,0 +1,157 @@
1
+ #! /usr/bin/ruby1.8
2
+
3
+ # == Synopsis
4
+ #
5
+ # snmpscan: a simple yet powerful snmp scanner
6
+ #
7
+ # == Usage
8
+ #
9
+ # snmpscan [OPTION] ip-range
10
+ #
11
+ # -h, --help:
12
+ # show help
13
+ #
14
+ # --timeout x, -t x:
15
+ # timeout x milliseconds (for faster scans), default 1 second
16
+ #
17
+ # --mib m, -m m:
18
+ # optional mib to use, defaults to sysDescr
19
+ #
20
+ # --comunity c, -c c
21
+ # comunity string, default "public"
22
+ #
23
+ # --protocol p, -p p
24
+ # version of the protocolo, defaults to 2c
25
+ #
26
+ # --version, -v
27
+ # version of the software
28
+ #
29
+ # --verbose, -V
30
+ # be verbose in output
31
+ #
32
+ # ip-range: An ip range (in the form 192.168.10.0/24)
33
+ # or a single address (172.30.16.1)
34
+ #
35
+ # == Examples
36
+ #
37
+ # snmpscan 10.10.10.64
38
+ # Scans host 10.10.10.64 with default values
39
+ #
40
+ # snmpscan -t 200 -c comread -m sysName 172.30.149.0/24
41
+ # Scans a range of 255 addresses for mib sysName.0, with comunity password "comread"
42
+ # and a timeout value of 200 milliseconds
43
+ #
44
+ # == Author and license
45
+ # Written by Marco Ceresa
46
+ # Distributed under the same license as Ruby is
47
+ #
48
+
49
+ $VERSION = 0.1
50
+
51
+ begin
52
+ require 'snmp'
53
+ rescue LoadError
54
+ require 'rubygems'
55
+ require_gem 'snmp'
56
+ end
57
+ require 'ipaddr'
58
+ require 'timeout'
59
+ require 'getoptlong'
60
+ require 'rdoc/usage'
61
+ require 'thwait'
62
+
63
+ opts = GetoptLong.new([ '--help', '-h', GetoptLong::NO_ARGUMENT ],
64
+ [ '--version', '-v', GetoptLong::NO_ARGUMENT ],
65
+ [ '--verbose', '-V', GetoptLong::NO_ARGUMENT ],
66
+ [ '--timeout', '-t', GetoptLong::REQUIRED_ARGUMENT ],
67
+ [ '--mib', '-m', GetoptLong::REQUIRED_ARGUMENT ],
68
+ [ '--protocol', '-p', GetoptLong::REQUIRED_ARGUMENT ],
69
+ [ '--comunity', '-c', GetoptLong::REQUIRED_ARGUMENT ]
70
+ )
71
+
72
+ # Defaults
73
+ timeout = 1000
74
+ mib = "sysDescr.0"
75
+ protocol = "2c"
76
+ comunity = "public"
77
+ verbose = false
78
+
79
+ opts.each do |opt, arg|
80
+ case opt
81
+ when '--help'
82
+ RDoc::usage
83
+ when '--version'
84
+ puts "snmpscan, version #$VERSION"
85
+ exit 0
86
+ when '--timeout'
87
+ timeout = arg.to_i
88
+ when '--mib'
89
+ mib = arg
90
+ unless mib =~ /\.\d+$/
91
+ mib += ".0"
92
+ end
93
+ when '--protocol'
94
+ protocol = arg
95
+ when '--comunity'
96
+ comunity = arg
97
+ when '--verbose'
98
+ verbose = true
99
+ end
100
+ end
101
+
102
+ puts "\nSNMP Scanner v.#$VERSION (c) Marco Ceresa 2006"
103
+ puts "Reference at http://snmpscan.rubyforge.org/"
104
+ print "Starting scanner for #{ARGV[0]} at #{Time.now}\n\n"
105
+
106
+ if ARGV.length != 1
107
+ print "\nMissing ip-range argument (try --help)\n\n"
108
+ exit 0
109
+ end
110
+
111
+ args = [timeout,mib,protocol,comunity]
112
+ print "Arguments: #{args.join ' '}\n\n" if verbose
113
+
114
+ class IPAddr
115
+ # The broadcast method calculate the broadcast
116
+ # address of the range (if any)
117
+ def broadcast
118
+ return @addr + (IPAddr::IN4MASK - @mask_addr)
119
+ end
120
+ # The each_address method iterates over each address
121
+ # of the ip range
122
+ def each_address
123
+ (@addr..broadcast).each do |addr|
124
+ yield _to_string(addr)
125
+ end
126
+ end
127
+ end
128
+
129
+ iprange = IPAddr.new(ARGV.shift,Socket::AF_INET)
130
+ threads = []
131
+ $stdout.sync = true
132
+
133
+
134
+
135
+ iprange.each_address do |ip|
136
+ begin
137
+ threads << Thread.new(ip,args) do |ip,args|
138
+ timeout,mib,protocol,comunity = args
139
+ begin
140
+ SNMP::Manager.open(:Host => ip,
141
+ :Community => comunity,
142
+ :Port => 161,
143
+ :Timeout => (timeout/1000.0)) do |man|
144
+ res = man.get([mib])
145
+ answer = res.varbind_list[0].value
146
+ print "#{ip}:\t#{answer}\n"
147
+ end
148
+ rescue
149
+ print "#{ip}:\t#$!\n" if verbose
150
+ end
151
+ end
152
+ rescue
153
+ next
154
+ end
155
+ end
156
+
157
+ ThreadsWait.all_waits(threads)
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: snmpscan
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.1"
7
+ date: 2006-05-26 00:00:00 +02:00
8
+ summary: A fast SNMP scanner
9
+ require_paths:
10
+ - lib
11
+ email: ceresa@gmail.com
12
+ homepage: http://snmpscan.rubyforge.org/
13
+ rubyforge_project:
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Marco Ceresa
30
+ files:
31
+ - bin/snmpscan
32
+ - README
33
+ test_files: []
34
+
35
+ rdoc_options: []
36
+
37
+ extra_rdoc_files:
38
+ - README
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ requirements: []
44
+
45
+ dependencies:
46
+ - !ruby/object:Gem::Dependency
47
+ name: snmp
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Version::Requirement
50
+ requirements:
51
+ - - ">"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.0
54
+ version: