ipscan 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ipscan.rb +77 -20
- data/lib/ipscan/cli.rb +3 -3
- data/lib/ipscan/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28f0852ab8dc39016f37d4e781441b5c74e27d98
|
4
|
+
data.tar.gz: 25e3f199daaa1504e888e49ba78c5479c02c2382
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 985db2876f5d07380465e5b2403e0d8dcc6a9613dbe54507748b9e3bbada9ddf0e878fe69b6927436e07bb101165b0271f27a061e0df2dd1c9cc3549c6af2ca1
|
7
|
+
data.tar.gz: b8bdef4f08be552a0a601da6867a1eafb8a9152243448c6c8ca3cf2d75cc1a2dde6bbf3ef4df9fb042f5d1d2d7aec6eb29ca3fdd21ed565eae139a5b73255625
|
data/lib/ipscan.rb
CHANGED
@@ -10,40 +10,97 @@ require 'ruby-progressbar'
|
|
10
10
|
|
11
11
|
module IPScan
|
12
12
|
|
13
|
-
def self.
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def self.arp(ip)
|
14
|
+
case RbConfig::CONFIG['host_os']
|
15
|
+
when /linux/i
|
16
|
+
line = `arp #{ip}`.split("\n").last.split(" ")
|
17
|
+
return {name: line[0], mac: line[2]}
|
18
|
+
when /bsd|osx|mach|darwin/i
|
19
|
+
line = `arp #{ip}`.split("\n").last.split(" ")
|
20
|
+
return {name: line[0], mac: line[3]}
|
21
|
+
else
|
22
|
+
raise "host_os=#{RbConfig::CONFIG['host_os']} are not supported"
|
17
23
|
end
|
18
|
-
|
24
|
+
end
|
19
25
|
|
26
|
+
def self.get_range_addresses(network_addr, start_host, last_host)
|
20
27
|
addrs = []
|
21
|
-
|
22
|
-
addrs << "#{
|
28
|
+
start_host.upto(last_host) do |i|
|
29
|
+
addrs << "#{network_addr}.#{i}"
|
23
30
|
end
|
31
|
+
addrs
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.get_netbios_info(range)
|
35
|
+
nbtinfo = {}
|
36
|
+
body_started = false
|
37
|
+
result = `nbtscan #{range}`
|
38
|
+
result.each_line do |line|
|
39
|
+
if line.index("-----------")
|
40
|
+
body_started = true
|
41
|
+
next
|
42
|
+
end
|
43
|
+
next unless body_started
|
44
|
+
h = line.split(" ")
|
45
|
+
ip = h[0]
|
46
|
+
netbios_name = h[1]
|
47
|
+
nbtinfo[ip] = {netbios_name: netbios_name}
|
48
|
+
end
|
49
|
+
nbtinfo
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.scan(renge)
|
53
|
+
unless renge.index("-")
|
54
|
+
renge = renge + "-254"
|
55
|
+
end
|
56
|
+
scan_result = renge.scan(/(.*)-(.*)/)[0]
|
57
|
+
network_addr = scan_result[0].split(".")[0..2].join(".")
|
58
|
+
start_host = scan_result[0].split(".")[3].to_i
|
59
|
+
last_host = scan_result[1].to_i
|
60
|
+
host_total = (start_host..last_host).size
|
61
|
+
puts "check #{network_addr}.#{start_host} ~ #{network_addr}.#{last_host}"
|
62
|
+
|
63
|
+
netbios_info = {}
|
64
|
+
if `which nbtscan` != ""
|
65
|
+
netbios_info = get_netbios_info(range)
|
66
|
+
end
|
67
|
+
|
68
|
+
addrs = get_range_addresses(network_addr, start_host, last_host)
|
24
69
|
|
25
70
|
results = []
|
26
|
-
progressbar = ProgressBar.create(:total =>
|
71
|
+
progressbar = ProgressBar.create(:total => host_total)
|
27
72
|
Parallel.each(addrs, in_threads: 100) do |addr|
|
28
73
|
data = {:ip => addr}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
data[:name] =
|
38
|
-
|
39
|
-
|
74
|
+
data.merge!(arp(addr))
|
75
|
+
pinger = Net::Ping::External.new(addr)
|
76
|
+
if pinger.ping?
|
77
|
+
arp_line = `arp #{addr}`
|
78
|
+
arp_hash = arp_line.split(" ")
|
79
|
+
if arp_hash[0] == "?"
|
80
|
+
data[:name] = "<unknown>"
|
81
|
+
else
|
82
|
+
data[:name] = arp_hash[0]
|
83
|
+
end
|
84
|
+
|
85
|
+
if arp_line.index("no entry")
|
86
|
+
data[:mac] = "<no entry> "
|
87
|
+
else
|
88
|
+
data[:mac] = arp_hash[3]
|
89
|
+
end
|
90
|
+
|
91
|
+
if netbios_info[addr]
|
92
|
+
data[:netbios_name] = netbios_info[addr][:netbios_name]
|
93
|
+
else
|
94
|
+
data[:netbios_name] = "<unknown>"
|
40
95
|
end
|
96
|
+
results << data
|
41
97
|
end
|
42
98
|
progressbar.increment
|
43
99
|
end
|
44
100
|
|
101
|
+
puts "IP Address \tMac Address \tName \tNetBIOS Name"
|
45
102
|
results.each do |res|
|
46
|
-
puts "#{res[:ip]}\t#{res[:mac]}\t#{res[:name]}"
|
103
|
+
puts "#{res[:ip]} \t#{res[:mac]} \t#{res[:name]} \t#{res[:netbios_name]}"
|
47
104
|
end
|
48
105
|
end
|
49
106
|
end
|
data/lib/ipscan/cli.rb
CHANGED
@@ -4,9 +4,9 @@ require 'thor'
|
|
4
4
|
|
5
5
|
module IPScan
|
6
6
|
class CLI < Thor
|
7
|
-
desc "
|
8
|
-
def
|
9
|
-
IPScan.scan(
|
7
|
+
desc "range [SCAN_RANGE]", "scan 192.168.1.0-254"
|
8
|
+
def range(range)
|
9
|
+
IPScan.scan(range)
|
10
10
|
end
|
11
11
|
|
12
12
|
default_task :scan
|
data/lib/ipscan/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ipscan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- k-yamada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|