मैं ऐसे कई वातावरण वाले वातावरण में हूं जो उचित रूप से आविष्कार नहीं किए गए हैं। असल में, कोई भी नहीं जानता कि कौन सा आईपी जाता है जिसके साथ मैक पता और कौन सा होस्टनाम है। तो मैंने निम्नलिखित लिखा:रूबी में डीएनएस रिवर्स?
# This script goes down the entire IP range and attempts to
# retrieve the Hostname and mac address and outputs them
# into a file. Yay!
require "socket"
TwoOctets = "10.26"
def computer_exists?(computerip)
system("ping -c 1 -W 1 #{computerip}")
end
def append_to_file(line)
file = File.open("output.txt", "a")
file.puts(line)
file.close
end
def getInfo(current_ip)
begin
if computer_exists?(current_ip)
arp_output = `arp -v #{current_ip}`
mac_addr = arp_output.to_s.match(/..:..:..:..:..:../)
host_name = Socket.gethostbyname(current_ip)
append_to_file("#{host_name[0]} - #{current_ip} - #{mac_addr}\n")
end
rescue SocketError => mySocketError
append_to_file("unknown - #{current_ip} - #{mac_addr}")
end
end
(6..8).each do |i|
case i
when 6
for j in (1..190)
current_ip = "#{TwoOctets}.#{i}.#{j}"
getInfo(current_ip)
end
when 7
for j in (1..255)
current_ip = "#{TwoOctets}.#{i}.#{j}"
getInfo(current_ip)
end
when 8
for j in (1..52)
current_ip = "#{TwoOctets}.#{i}.#{j}"
getInfo(current_ip)
end
end
end
सब कुछ काम करता है इसके अलावा एक रिवर्स DNS नहीं मिलता है।
10.26.6.12 - 10.26.6.12 - 00:11:11:9B:13:9F
10.26.6.17 - 10.26.6.17 - 08:00:69:9A:97:C3
10.26.6.18 - 10.26.6.18 - 08:00:69:93:2C:E2
अगर मैं nslookup 10.26.6.12
तो मैं सही रिवर्स DNS मिलता है तो पता चलता है कि मेरी मशीन DNS सर्वर देख रही है:
नमूना उत्पादन है कि मैं हो रही है यह है।
मैंने Socket.gethostbyname
, gethostbyaddr
को आजमाया है, लेकिन यह काम नहीं करता है।
कोई मार्गदर्शन बहुत सराहना की जाएगी।
वास्तव में यह रिवर्स लुकअप नहीं कर रहा है। आपको 7 वें पैरामीटर 'सत्य' बनाने की आवश्यकता है: 'सॉकेट.getaddrinfo (दिलचस्प_आईपी, 0, सॉकेट :: AF_UNSPEC, सॉकेट :: SOCK_STREAM, शून्य, सॉकेट :: AI_CANONNAME, सत्य) ' – akostadinov