Skip to content

Instantly share code, notes, and snippets.

@btm
Created August 4, 2014 19:23
Show Gist options
  • Save btm/7be7c484b8d8ce737441 to your computer and use it in GitHub Desktop.
Save btm/7be7c484b8d8ce737441 to your computer and use it in GitHub Desktop.
# Test DNS on Windows
wmi = WmiLite::Wmi.new
host = wmi.first_of('Win32_ComputerSystem')
hostname = "#{host['name']}"
machinename = "#{host['name']}"
x = 0
while x < 10
info = Socket.gethostbyname(Socket.gethostname)
if info.first =~ /.+?\.(.*)/
puts "fqdn found via gethostbyname: #{info.first}"
else
#host is not in dns. optionally use:
#C:\WINDOWS\system32\drivers\etc\hosts
fqdn = Socket.gethostbyaddr(info.last).first
puts "fqdn found via gethostbyaddr: #{fqdn}"
end
x = x + 1
sleep 5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment