This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

dns lookup
#1
Hi,

  what is the function to resolve the dns name of a site (similar to nslookup) ?

I 'm looking for a script to obtain the IP address from a name server.

BR,
Alberto
KNX Advanced Partner + Tutor
Reply
#2
Use this:
Code:
function resolve(domain)
  local sock = require('socket').udp()
  local res

  if sock:setpeername(domain, 123) then
    res = sock:getpeername()
  end

  sock:close()
  return res
end

ip = resolve('openrb.com')
log(ip)
Reply
#3
Thanks...TOP
KNX Advanced Partner + Tutor
Reply
#4
Hi,

I've tried suggested code but it returns only single IP for a domain. Is there a way to get all resolved IPs for a given name?
also how resource intensive for LM is to resolve dozens (double digit number) names in a script? or it's best to offload this task to another platform?
Reply
#5
There's no way of getting all IP addresses for a given host. Why do you need to get all? If some kind of load balancing is used then the list is not static and can change over time.
DNS requests are very lightweight and should not cause high load. You can put a small delay between them so there are no CPU load spikes.
Reply
#6
(20.02.2023, 11:03)admin Wrote: There's no way of getting all IP addresses for a given host. Why do you need to get all? If some kind of load balancing is used then the list is not static and can change over time.
DNS requests are very lightweight and should not cause high load. You can put a small delay between them so there are no CPU load spikes.

I'm building a bot to manage dns-based ip routes on the router (vpn tunnel), for this reason i need all returned IPs by a single DNS query (like if you do nslookup). I understand there're some sites that are using dns round robin with 10+ addresses, but most of them are using 2-3 static and i want to make sure i add all of them to the routing policy.
Reply
#7
You can run nslookup via os.execute().
Reply
#8
(22.02.2023, 14:15)admin Wrote: You can run nslookup via os.execute().

but that's gonna be more expensive for tens of lookups than network lookups, right?
Reply
#9
Yes but I doubt that you need to execute them all the time.
Reply
#10
(22.02.2023, 14:18)admin Wrote: Yes but I doubt that you need to execute them all the time.

if i have a collection of 30 domain names that should be tunneled, i need to refresh them from time to time, for that i need to do 30 lookups one after another in a single run. Ok thanks for the info, i think i've got an idea

Here's the code i'm using and after that i need to parse response

Code:
handle = io.popen('nslookup domainname.com')
str = handle:read('*a')
handle:close()
log(str)
Reply


Forum Jump: