yptools 1.1.0 → 1.1.2

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
  SHA256:
3
- metadata.gz: 98dd6d1d9b7cc1c72d121fce68e65a6d035ebef4bab15b3fd18c0b550c2e23ec
4
- data.tar.gz: 3ddc62e82485cf62bf760a091b73d96769616e45d52de26cf98de7ca2eeb45e2
3
+ metadata.gz: 8408e5e1a3c11b120fb7f35959032380a30e25363b87b24ed8db7aeed71682e3
4
+ data.tar.gz: f13a54118992f2b3629895a2cf48b82ec401c66d8eb5e351977d5f07aca1a00a
5
5
  SHA512:
6
- metadata.gz: b3138ef32c117ca0c53f553fe0b1a95500369fcc186e1a60a569980e1efcaeae041de2c95f4324906162e8d6f780f450df3358f998261aa0f158f004ee740a58
7
- data.tar.gz: 0cc0a0b57eb2c8ee090c1f7501342948457397fbc72f91a14d9919dcd09a0a9c80d23a7b64007b026c354db6ff7e76f17d0f5f4d3fe882afce98edf1208f4a7e
6
+ metadata.gz: 5e49cce07a4d0bfafc800d8cfa3d65a1ea826732bd3f0e8710e987d99f71bc97c6c35268096a6383ef1118ad4fe1861f3305800fc6e086055d1a0ee4fc30403f
7
+ data.tar.gz: afef0a6c693d3ba8c0ed26838a5364c5d3a0b7837adbe9e3c60fab27b7f2e4f411f9c74b11dee3e96cab81003840d8d4de6b7e80f8d8cb5212bd16ac05d2e525
@@ -3,11 +3,13 @@ class YPHelp
3
3
  def self.message
4
4
  puts %q{
5
5
 
6
+ 🤖🤖🤖 - 智能聊天、绘画(OpenAI)
6
7
  chatgpt: use [yptools chatgpt] 创建会话列表与 chatgpt 聊天,会记录上下内容(科学上网)
7
8
  [yptools chatgpt ...] 快速与 chatgpt 沟通,不会记录上下内容
8
9
 
9
10
  openai: use [yptools openaiimg ...] 根据文本描述生成图像(eg: yptools openaiimg '老虎和狮子大战' )
10
11
 
12
+ 🚀🚀🚀 - iOS开发者(IOS Developer)
11
13
  autocre: use [yptools autocre ...] 自动化工具命令
12
14
  use [yptools autocre -objc ...] 根据 json 自动创建 Objective-C 数据库操作文件 .h|.m 文件。(依赖三方库 FMDB )
13
15
  use [yptools autocre -init] 构建数据库操作文件的json模板
@@ -25,8 +27,14 @@ class YPHelp
25
27
  xpj: use [yptools xpj ...] use xcodeproj api
26
28
  use [yptools xpj check] 检查当前目录项目文件是否存在引用的问题
27
29
 
28
- help: use [yptools help] 查看帮助
30
+ 🤡🤡🤡 - hacker
31
+ portscan: use [yptools portscan <ip地址或域名> [<端口范围>]] 扫描指定 IP 端口是否开放
29
32
 
33
+ scanlocalips: use [yptools scanlocalips] 扫描本地局域网下所有 IP
34
+
35
+ 💩💩💩 - 帮助(help)
36
+ help: use [yptools help] 查看帮助
37
+
30
38
  }
31
39
  end
32
40
 
@@ -0,0 +1,50 @@
1
+ class YPPortScan
2
+ def self.portscan(port, range)
3
+ script = %Q(
4
+ #!/bin/bash
5
+
6
+ if [ -n "#{range}" ]; then
7
+ all_port="#{range}"
8
+ else
9
+ all_port="1-65535"
10
+ fi
11
+
12
+ port_range=(${all_port//-/ })
13
+ timeout=0.02
14
+ ip_address=#{port}
15
+
16
+ port_range+=(#{range})
17
+
18
+ echo "正在扫描 ${ip_address} 的端口 ${port_range[0]} 到 ${port_range[1]}..."
19
+ echo ${port_range[1]}
20
+
21
+ open_ports=()
22
+ closed_ports=()
23
+
24
+ for ((port = ${port_range[0]}; port <= ${port_range[1]}; port++)); do
25
+ (echo >/dev/tcp/${ip_address}/${port}) >/dev/null 2>&1 &
26
+ pid=$!
27
+ (
28
+ sleep ${timeout}
29
+ kill ${pid} >/dev/null 2>&1
30
+ ) &
31
+ timer=$!
32
+ if wait ${pid} 2>/dev/null; then
33
+ echo "\\033[32m${port} 是开放的\\033[0m"
34
+ open_ports+=($port)
35
+ else
36
+ echo "\\033[31m${port} 是关闭的\\033[0m"
37
+ closed_ports+=($port)
38
+ fi
39
+ kill ${timer} >/dev/null 2>&1
40
+ done
41
+
42
+ allCount=$((${#open_ports[@]} + ${#closed_ports[@]}))
43
+
44
+ echo ${allCount} "个端口扫描完成。"
45
+ echo "共有 ${#open_ports[@]} 个端口是开放的,${#closed_ports[@]} 个端口是关闭的。"
46
+ echo "开放的端口: " "\\033[32m${open_ports[@]}\\033[0m"
47
+ )
48
+ system(script)
49
+ end
50
+ end
@@ -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
@@ -11,6 +11,8 @@ require_relative 'yptools/package/yp_package'
11
11
  require_relative 'yptools/autocre/yp_autocre'
12
12
  require_relative 'yptools/autocre/yp_autoinit'
13
13
  require_relative 'yptools/chatai/yp_chatai'
14
+ require_relative 'yptools/portscan/yp_portscan'
15
+ require_relative 'yptools/scanlocalips/yp_scanlocalips'
14
16
 
15
17
  class YPTools
16
18
 
@@ -102,6 +104,15 @@ class YPTools
102
104
  yp_log_fail "'yptools xpj ..' 参数缺失"
103
105
  self.help
104
106
  end
107
+ when 'portscan'
108
+ if argvs.size > 1
109
+ self.portscan argvs
110
+ else
111
+ yp_log_fail "'yptools portscan ..' 参数缺失"
112
+ self.help
113
+ end
114
+ when 'scanlocalips'
115
+ self.scanlocalips
105
116
  else
106
117
  self.help
107
118
  end
@@ -158,6 +169,16 @@ class YPTools
158
169
  YPChatAI.openaiimg(message)
159
170
  end
160
171
 
172
+ def self.portscan(argvs)
173
+ port = argvs[1]
174
+ range = argvs[2]
175
+ YPPortScan.portscan(port,range)
176
+ end
177
+
178
+ def self.scanlocalips()
179
+ YPScanLocalIPs.scanlocalips()
180
+ end
181
+
161
182
  end
162
183
 
163
184
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yptools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - chenghengsheng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-10 00:00:00.000000000 Z
11
+ date: 2023-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -141,6 +141,8 @@ files:
141
141
  - lib/yptools/log/yp_log.rb
142
142
  - lib/yptools/mgc/yp_makegarbagecode.rb
143
143
  - lib/yptools/package/yp_package.rb
144
+ - lib/yptools/portscan/yp_portscan.rb
145
+ - lib/yptools/scanlocalips/yp_scanlocalips.rb
144
146
  - lib/yptools/update/yp_update.rb
145
147
  - lib/yptools/xcodeproj/yp_xcodeproj.rb
146
148
  homepage: https://github.com/HansenCCC/YPTools.git