I am writing a program to use dnsmasq as a tool to perform dns querry.
I was able to write some functions like those:
void writeConfiguration(string a stringValue){
//open etc/dnsmasq.conf
//write a string with keywords such as listening_address = 127.0.0.1 to setup dnsmasq
}
void writeResolve(string a stringCommand){
//open etc/dnsmasq.conf
//write a string with keywords such as nameserver= 127.0.0.1 to setup dnsmasq to look up local cache first
}
On Linux terminal, I could run some command such as dig stackoverflow, host facebook.com, or use a web browser to actually perform dns query and check if my dnsmasq setup works.
However, I would like to invoke the action DNS query from code. The function use dnsmasq and has to return the IP address of the hostname in an array integer or some data struct.
My idea is that I could wrap a linux command with within my function by passing string to Posix api such as run_cmd.
The code could be something like this:
#include "utils/PosixCmd.h" //include this to use run_cmd
std::string tmpCmd;
(void)tmpCmd.append("dig facebook.com ");
(void)run_cmd(const_cast<char*>(tmpCmd.c_str()));
However, "did" doesn't return expected output. Does anyone know a Linux command that runs dns querry and returns a simple ip address ? In addition, the command has to use nameservers in etc/resolve.conf.
Or if it doesn't look up dns servers in etc/resolve.conf, what would be the option the change lookup file?
Aucun commentaire:
Enregistrer un commentaire