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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28f0852ab8dc39016f37d4e781441b5c74e27d98
4
- data.tar.gz: 25e3f199daaa1504e888e49ba78c5479c02c2382
3
+ metadata.gz: ded3eeb5f622d5c832c0057c2b386ccf9dbf6748
4
+ data.tar.gz: 6eb25877d599e51dad8110304661205e7eaf6919
5
5
  SHA512:
6
- metadata.gz: 985db2876f5d07380465e5b2403e0d8dcc6a9613dbe54507748b9e3bbada9ddf0e878fe69b6927436e07bb101165b0271f27a061e0df2dd1c9cc3549c6af2ca1
7
- data.tar.gz: b8bdef4f08be552a0a601da6867a1eafb8a9152243448c6c8ca3cf2d75cc1a2dde6bbf3ef4df9fb042f5d1d2d7aec6eb29ca3fdd21ed565eae139a5b73255625
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
- line = `arp #{ip}`.split("\n").last.split(" ")
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
- line = `arp #{ip}`.split("\n").last.split(" ")
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(renge)
53
- unless renge.index("-")
54
- renge = renge + "-254"
59
+ def self.scan(range)
60
+ unless range.index("-")
61
+ range = range + "-254"
55
62
  end
56
- scan_result = renge.scan(/(.*)-(.*)/)[0]
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
@@ -8,7 +8,5 @@ module IPScan
8
8
  def range(range)
9
9
  IPScan.scan(range)
10
10
  end
11
-
12
- default_task :scan
13
11
  end
14
12
  end
@@ -1,3 +1,3 @@
1
1
  module IPScan
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipscan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - k-yamada