I am using this c# librabry for nslookup to find nameservers of domains.Here is my c# code
public async System.Threading.Tasks.Task<List<NS>> RunCmd(params string[] domains)
{
List<NS> NSL = new List<NS>();
var lookup = new LookupClient();
lookup.EnableAuditTrail = true;
foreach (var item in domains)
{
var result = await lookup.QueryAsync(item, QueryType.NS);
// rootDomain = result.AllRecords.FirstOrDefault().DomainName.Value;
var nameServer = result.AuditTrail;
var record = Regex.Match(nameServer.ToString(), @"ns\d"+ "."+ item).Value;
NSL.Add(new NS { domainName=item,nameServers= record});
}
var workbook = new XLWorkbook();
workbook.AddWorksheet("sheetName");
var ws = workbook.Worksheet("sheetName");
int row = 1;
foreach (var item in NSL)
{
ws.Cell("A" + row.ToString()).Value = item.domainName.ToString();
ws.Cell("B" + row.ToString()).Value = item.nameServers.ToString();
row++;
}
string folderPath = "D:\\";
workbook.SaveAs(folderPath+"nameServer.xlsx");
return NSL;
}
So i pass an array of domains for which i need to know the nameservers and return them in a list also write them to an excel file in my local directory.I can't get the nameservers from the response (var nameServer) directly so i am using regex to split the nameservers from the string.So according to my current regex i am able to get the nameservers if they are ns1 and ns2 if they are anything other than this like ns1262 or ns2636 i just get an empty string from the regex.
Here are two different sample response that i get in the variable nameServer
; (2 server found)
;; Got answer:
;; ->>HEADER<<- opcode: Query, status: No Error, id: 29412
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
mobilecellvideo.com. IN NS
;; ANSWER SECTION:
mobilecellvideo.com. 66306 IN NS ns2.mobilecellvideo.com.
mobilecellvideo.com. 66306 IN NS ns1.mobilecellvideo.com.
;; Query time: 132 msec
;; SERVER: 106.51.113.3#53
;; WHEN: Mon, 13 Mar 2017 02:55:38 GMT
;; MSG SIZE rcvd: 73
and for the below response when i try to match the above regex i only get an empty string
; (2 server found)
;; Got answer:
;; ->>HEADER<<- opcode: Query, status: No Error, id: 29414
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
networkwonder.com. IN NS
;; ANSWER SECTION:
networkwonder.com. 300 IN NS ns2626.ztomy.com.
networkwonder.com. 300 IN NS ns1626.ztomy.com.
;; Query time: 436 msec
;; SERVER: 106.51.113.3#53
;; WHEN: Mon, 13 Mar 2017 03:09:01 GMT
;; MSG SIZE rcvd: 83
Any help would be really appreciated
Thanks in advance !