yptools 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8223853ebcd90eb9fcd7f20d91a01eaac8b926ee69e2291dbfe6ee9976eaec0
4
- data.tar.gz: 7605e3081dbb09c6d4cc654431e0341a0fb9b21c039d4134ca4c71f1512d42c5
3
+ metadata.gz: 8408e5e1a3c11b120fb7f35959032380a30e25363b87b24ed8db7aeed71682e3
4
+ data.tar.gz: f13a54118992f2b3629895a2cf48b82ec401c66d8eb5e351977d5f07aca1a00a
5
5
  SHA512:
6
- metadata.gz: 7c3e46af8e5bbc9e380976f96b33e09a6a2c938d95e4bf8954fab587b3378af78d2f56b4013fa359a7b11d95317aa4e1a66c67a4148bfe3654da6013a91ac430
7
- data.tar.gz: 01e1e766ea8dcf4a48e0862376c279847214cbeaf3aeadd511e92ece81945d50ce1ce8f29ee57266cb14d7acf42073d0094d7331e59ede4c6613c519114b6a12
6
+ metadata.gz: 5e49cce07a4d0bfafc800d8cfa3d65a1ea826732bd3f0e8710e987d99f71bc97c6c35268096a6383ef1118ad4fe1861f3305800fc6e086055d1a0ee4fc30403f
7
+ data.tar.gz: afef0a6c693d3ba8c0ed26838a5364c5d3a0b7837adbe9e3c60fab27b7f2e4f411f9c74b11dee3e96cab81003840d8d4de6b7e80f8d8cb5212bd16ac05d2e525
@@ -29,6 +29,8 @@ class YPHelp
29
29
 
30
30
  🤡🤡🤡 - hacker
31
31
  portscan: use [yptools portscan <ip地址或域名> [<端口范围>]] 扫描指定 IP 端口是否开放
32
+
33
+ scanlocalips: use [yptools scanlocalips] 扫描本地局域网下所有 IP
32
34
 
33
35
  💩💩💩 - 帮助(help)
34
36
  help: use [yptools help] 查看帮助
@@ -0,0 +1,44 @@
1
+ require 'socket'
2
+
3
+ class YPScanLocalIPs
4
+
5
+ def self.scanlocalips()
6
+ self.scan_local_ips
7
+ end
8
+
9
+ def self.ping(ip)
10
+ IO.popen("ping -c 1 -t 1 #{ip} > /dev/null 2>&1") { |f| f.close }
11
+ if $?.exitstatus == 0
12
+ puts ip
13
+ elsif $?.exitstatus == 2
14
+ # No route to host
15
+ elsif $?.exitstatus == 68
16
+ # Name or service not known
17
+ end
18
+ rescue => e
19
+ # handle exception
20
+ end
21
+
22
+ def self.scan_local_ips
23
+ # 获取本机IP地址前三位,例如 192.168.0
24
+ prefix = Socket.ip_address_list.find { |intf| intf.ipv4? && !intf.ipv4_loopback? }.ip_address.split('.')[0, 3].join('.') + '.'
25
+ threads = []
26
+
27
+ # 遍历所有可能的IP地址
28
+ (1..255).each do |i|
29
+ threads << Thread.new(prefix, i) do |pr, j|
30
+ # 组合出IP地址,例如 192.168.0.1
31
+ ip = "#{pr}#{j}"
32
+ # 使用ping命令测试是否能够ping通,并手动关闭文件句柄
33
+ ping(ip)
34
+ end
35
+ end
36
+
37
+ # 等待所有线程执行完毕
38
+ threads.each(&:join)
39
+
40
+ # 输出所有结果
41
+ results = threads.map(&:value).compact
42
+ results.each { |ip| puts ip + "🚀" }
43
+ end
44
+ end
data/lib/yptools.rb CHANGED
@@ -12,6 +12,7 @@ require_relative 'yptools/autocre/yp_autocre'
12
12
  require_relative 'yptools/autocre/yp_autoinit'
13
13
  require_relative 'yptools/chatai/yp_chatai'
14
14
  require_relative 'yptools/portscan/yp_portscan'
15
+ require_relative 'yptools/scanlocalips/yp_scanlocalips'
15
16
 
16
17
  class YPTools
17
18
 
@@ -110,6 +111,8 @@ class YPTools
110
111
  yp_log_fail "'yptools portscan ..' 参数缺失"
111
112
  self.help
112
113
  end
114
+ when 'scanlocalips'
115
+ self.scanlocalips
113
116
  else
114
117
  self.help
115
118
  end
@@ -172,6 +175,10 @@ class YPTools
172
175
  YPPortScan.portscan(port,range)
173
176
  end
174
177
 
178
+ def self.scanlocalips()
179
+ YPScanLocalIPs.scanlocalips()
180
+ end
181
+
175
182
  end
176
183
 
177
184
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yptools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - chenghengsheng
@@ -142,6 +142,7 @@ files:
142
142
  - lib/yptools/mgc/yp_makegarbagecode.rb
143
143
  - lib/yptools/package/yp_package.rb
144
144
  - lib/yptools/portscan/yp_portscan.rb
145
+ - lib/yptools/scanlocalips/yp_scanlocalips.rb
145
146
  - lib/yptools/update/yp_update.rb
146
147
  - lib/yptools/xcodeproj/yp_xcodeproj.rb
147
148
  homepage: https://github.com/HansenCCC/YPTools.git