yptools 1.1.3 → 1.1.4

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: a823a2bc7da0e01f28d2c0d70f268c4641970dd7681609ebd6f58c1fa89bdaaf
4
- data.tar.gz: 1cc88e0353cb745bb043f06115a0556514d72f6365daf4a931599227d410d731
3
+ metadata.gz: c49bfe04d254b19d13b80a1e9f5db8ffe4b5d44ec6008d304b6f867bee00e66b
4
+ data.tar.gz: 036e0974cc6ebe80b186c43f5ede5f39088d17847563391e7084f81c4d94a487
5
5
  SHA512:
6
- metadata.gz: b9ddd0a94e0aa79b51d835827a4eb5017527e1ef43f4e3f647c04de43fd6574c0f5a12f8216897de8926feea9d772d2b46dcfa1b54050040854bede8003941df
7
- data.tar.gz: b04456427417ca5df62a22317f24d9267aa79f0a74fd00ade655ed4f9b823cc17d588b07e7c310e2fd05f6d690433528766c1d85a70d291caec6be813adc333d
6
+ metadata.gz: a22f3e20325311844302d284987884261b4fc61e1de3cde94d5feb969a0653b843a09c270a6bedce162ecdf13d9f30d649723dbbec4da6a936c1c577bb398a32
7
+ data.tar.gz: 20daa32b7722a94e5e25c7b883e0ab6546698463a74256f73b6a4a770233295f24b2f7d504563db71c94d2738b0e045c76726db2352607ab68a3331fa8c60b41
@@ -1,50 +1,35 @@
1
+ require 'colored'
2
+
1
3
  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
4
+ COMMON_PORTS = [21, 22, 23, 25, 53, 80, 81, 88, 110, 111, 135, 139, 143, 161, 389, 443, 445, 465, 514, 587, 631, 993, 995, 1080, 1194, 1433, 1521, 2049, 2082, 2083, 2181, 2222, 2375, 2376, 3389, 3690, 4443, 5432, 5900, 5984, 6379, 7001, 7002, 8080, 8081, 8086, 8443, 8888, 9090, 9200, 9300, 10000, 11211, 15672, 27017, 28017, 50000, 50070, 50075, 50090]
5
+
6
+ def self.portscan(address, range)
7
+ ip_address = address
8
+ if range.nil? || range.empty? || range == "-d" || range == "-default"
9
+ port_range = COMMON_PORTS
10
+ yp_log_doing "正在扫描 #{ip_address} 常用的端口"
11
+ else
12
+ temp_port_range = range.split("-").map(&:to_i)
13
+ yp_log_doing "正在扫描 #{ip_address} 的端口 #{temp_port_range.min} 到 #{temp_port_range.max}..."
14
+ port_range = temp_port_range.size == 1 ? [temp_port_range[0]] : (temp_port_range[0]..temp_port_range[1]).to_a
15
+ end
11
16
 
12
- port_range=(${all_port//-/ })
13
- timeout=0.02
14
- ip_address=#{port}
17
+ open_ports = []
18
+ closed_ports = []
15
19
 
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)
20
+ port_range.each do |port|
21
+ `nc -w 1 -z #{ip_address} #{port} 2>&1 | grep succeeded`
22
+ if $?.success?
23
+ yp_log_success "#{port} 是开放的"
24
+ open_ports << port
25
+ else
26
+ yp_log_fail "#{port} 是关闭的"
27
+ closed_ports << port
28
+ end
49
29
  end
30
+
31
+ all_count = open_ports.size + closed_ports.size
32
+ yp_log_doing "共有 #{open_ports.size} 个端口是开放的,#{closed_ports.size} 个端口是关闭的。"
33
+ yp_log_success "#{all_count} 个端口扫描完成," + "开放的端口: #{open_ports}"
34
+ end
50
35
  end
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.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - chenghengsheng