ipscan 0.0.2 → 0.0.3
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 +18 -25
- data/lib/ipscan/cli.rb +0 -2
- data/lib/ipscan/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ded3eeb5f622d5c832c0057c2b386ccf9dbf6748
|
4
|
+
data.tar.gz: 6eb25877d599e51dad8110304661205e7eaf6919
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 014485d8093c799e81948f2df012ab6ad87dc115e117f9fb069204b41a337c41af1cb426e5abd4c35cac0bc2e0832ed63dd245d2ad71f177b7d0d27beea83fbc
|
7
|
+
data.tar.gz: 52530e90db616217612f8000dae7acd8f4cb14476079d6fc7a017fac1221ca759edea07d902f0b2c79e1db50b80b03ce70674fdb563903bca6b1f883f223fafb
|
data/lib/ipscan.rb
CHANGED
@@ -5,22 +5,29 @@ require 'net/ping'
|
|
5
5
|
require 'socket'
|
6
6
|
require 'ruby-progressbar'
|
7
7
|
|
8
|
-
# http://shokai.org/blog/archives/7723
|
9
|
-
# http://docs.ruby-ipscang.org/ja/1.9.3/method/Socket/s/gethostbyname.html
|
10
|
-
|
11
8
|
module IPScan
|
12
9
|
|
13
10
|
def self.arp(ip)
|
11
|
+
data = {}
|
12
|
+
arp_line = `arp #{ip}`.split("\n").last
|
13
|
+
arp_hash = arp_line.split(" ")
|
14
14
|
case RbConfig::CONFIG['host_os']
|
15
15
|
when /linux/i
|
16
|
-
|
17
|
-
return {name: line[0], mac: line[2]}
|
16
|
+
data = {name: arp_hash[0], mac: arp_hash[2]}
|
18
17
|
when /bsd|osx|mach|darwin/i
|
19
|
-
|
20
|
-
return {name: line[0], mac: line[3]}
|
18
|
+
data = {name: arp_hash[0], mac: arp_hash[3]}
|
21
19
|
else
|
22
20
|
raise "host_os=#{RbConfig::CONFIG['host_os']} are not supported"
|
23
21
|
end
|
22
|
+
|
23
|
+
if data[:name]== "?"
|
24
|
+
data[:name] = "<unknown>"
|
25
|
+
end
|
26
|
+
|
27
|
+
if arp_line.index("no entry")
|
28
|
+
data[:mac] = "<no entry> "
|
29
|
+
end
|
30
|
+
data
|
24
31
|
end
|
25
32
|
|
26
33
|
def self.get_range_addresses(network_addr, start_host, last_host)
|
@@ -49,11 +56,11 @@ module IPScan
|
|
49
56
|
nbtinfo
|
50
57
|
end
|
51
58
|
|
52
|
-
def self.scan(
|
53
|
-
unless
|
54
|
-
|
59
|
+
def self.scan(range)
|
60
|
+
unless range.index("-")
|
61
|
+
range = range + "-254"
|
55
62
|
end
|
56
|
-
scan_result =
|
63
|
+
scan_result = range.scan(/(.*)-(.*)/)[0]
|
57
64
|
network_addr = scan_result[0].split(".")[0..2].join(".")
|
58
65
|
start_host = scan_result[0].split(".")[3].to_i
|
59
66
|
last_host = scan_result[1].to_i
|
@@ -74,20 +81,6 @@ module IPScan
|
|
74
81
|
data.merge!(arp(addr))
|
75
82
|
pinger = Net::Ping::External.new(addr)
|
76
83
|
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
84
|
if netbios_info[addr]
|
92
85
|
data[:netbios_name] = netbios_info[addr][:netbios_name]
|
93
86
|
else
|
data/lib/ipscan/cli.rb
CHANGED
data/lib/ipscan/version.rb
CHANGED