0
我有一個計劃,將ping一個IP地址,然後登錄的IP到一個文件,如果它成功地坪:重試不同的端口號
Invalid IP: 128.201.166.30
Proxy created: 66.25.173.128:80
Invalid IP: 225.195.111.59
Invalid IP: 249.133.221.70
Invalid IP: 40.21.11.99
Invalid IP: 201.27.136.108
Invalid IP: 152.77.109.45
Invalid IP: 120.76.159.122
Invalid IP: 108.244.67.42
Invalid IP: 73.231.16.193
Proxy created: 146.134.102.95:3128
Invalid IP: 133.216.1.59
Proxy created: 118.75.196.75:3128
現在我想要做的是有「好「IP地址使用的每個端口的以下數組中:port = %w(80 3128 8080 8090 8888 8898 9999)
,例如:
Proxy created: 66.25.173.128:80
Proxy created: 66.25.173.128:3128
Proxy created: 66.25.173.128:8080
Proxy created: 66.25.173.128:8090
Proxy created: 66.25.173.128:8888
Proxy created: 66.25.173.128:8898
Proxy created: 66.25.173.128:9999
#Creates an IP with a port extension with each port number
我想我有我怎麼能這樣一個總體思路:
File.open("example.txt", "a+"){
|s| s.puts("#{ip}:#{port[0]}",
"#{ip}:#{port[1]}",
"#{ip}:#{port[2]}"
#etc...
)}
我不完全確定這是否會按照我期待的方式工作,即使它的確如此,我100%肯定還有更好的方法可以做,任何幫助都將不勝感激,謝謝。
來源:
require 'colored'
require 'timeout'
def create_possibles
port = %w(80 3128 8080 8090 8888 8898 9999).each do |port|
10.times do
ip = Array.new(4){rand(256)}.join('.')
Timeout::timeout(5) do
ping = `ping -n 1 #{ip}`
if ping =~ /Received = 1/
proxy = "#{ip}:#{port}"
puts "Proxy created: #{proxy}".green.bold
File.open("proxies.txt", "a+") {|s| s.puts(proxy)}
else
puts "Invalid IP: #{ip}".red.bold
next
end
end
end
end
end
create_possibles
編輯:
我嘗試我的如何做到這一點的總體思路:
require 'colored'
require 'timeout'
def create_possibles
w%(80 3128 8080 8090 8888 8898 9999).each do |port|
1.times do
ip = Array.new(4){rand(256)}.join('.')
Timeout::timeout(5) do
ping = `ping -n 1 #{ip}`
if ping =~ /Received = 1/
# proxy = "#{ip}:#{port}"
puts "[SUCCESS]Proxy created for IP: #{ip}".green.bold
File.open("proxies.txt", "a+") {|s| s.puts("#{ip}:#{port[0]}",
"#{ip}:#{port[1]}",
"#{ip}:#{port[2]}",
"#{ip}:#{port[3]}",
"#{ip}:#{port[4]}",
"#{ip}:#{port[5]}",
"#{ip}:#{port[6]}",
"#{ip}:#{port[7]}")}
else
puts "[ERROR]IP failed to ping: #{ip}".red.bold
next
end
end
end
end
end
create_possibles
當運行:
[ERROR]IP failed to ping: 185.105.73.104
[ERROR]IP failed to ping: 93.182.117.11
[ERROR]IP failed to ping: 112.210.73.187
[ERROR]IP failed to ping: 111.109.127.178
[SUCCESS]Proxy created for IP: 201.153.205.131
[ERROR]IP failed to ping: 128.236.57.123
[ERROR]IP failed to ping: 248.84.17.31
它結束了輸出,看起來像這樣的信息:
201.153.205.131:0
201.153.205.131:0
201.153.205.131:0
201.153.205.131:1
201.153.205.131:1
201.153.205.131:1
201.153.205.131:0
201.153.205.131:1
對我來說很好... 問題是什麼?你有錯誤嗎? –
@maxpleaner不,我只是不是100%確定它是否可以工作,所以'#{port [0]}';'#{port [1]}'等等。按照我期望的方式工作嗎? – 13aal
你爲什麼不試試看?它看起來像是在製作一個pentesting應用程序,所以我理解不要運行錯誤代碼的願望,但總是需要運行代碼來查看它是否有效。然後你必須學會如何理解錯誤。 –