Board logo

标题: [文本处理] 如何使用Nslookup命令批量查询域名并且输出解析出来的IPv4到指定文本? [打印本页]

作者: adslcool    时间: 2016-1-14 14:46     标题: 如何使用Nslookup命令批量查询域名并且输出解析出来的IPv4到指定文本?

本帖最后由 pcl_test 于 2016-1-14 16:17 编辑

用批处理Nslookup批量查询域名并且输出解析出来的IPv4到指定文本


domain.txt
————————————————————
sz.tencent.com
sz2.tencent.com
sz3.tencent.com
sz4.tencent.com
sz5.tencent.com
————————————————————

dns.txt
————————————————————
114.114.114.114
114.114.115.115
223.5.5.5
223.6.6.6
180.76.76.76
————————————————————

domain.txt 里面的每行域名都用 dns.txt每行的DNS服务器查询一遍,然后输出查询到的IPv4到指定文本,如果已经存在则不添加。

nslookup sz.tencent.com 114.114.114.114  只取解析到的IP
________________________________

服务器:  public1.114dns.com
Address:  114.114.114.114

非权威应答:
名称:    sz.tencent.com
Addresses:  111.161.88.16
          111.161.88.38
          111.161.88.29
          111.161.88.12
          111.161.88.17
          111.161.88.13
          111.161.88.31
          111.161.88.30
          111.161.88.27
          111.161.88.28
          111.161.88.15
          111.161.88.18
          111.161.88.14
          111.161.88.11
          111.161.88.32
          111.161.88.34
________________________________

nslookup sz.tencent.com 114.114.114.114
nslookup sz.tencent.com 114.114.115.115
nslookup sz.tencent.com 223.5.5.5
nslookup sz.tencent.com 223.6.6.6
nslookup sz.tencent.com 180.76.76.76
作者: WHY    时间: 2016-1-14 19:43

  1. @if (0)==(0) echo off
  2. (for /f %%i in (domain.txt) do (
  3.     for /f %%j in (dns.txt) do nslookup %%i %%j
  4. )) | cscript //nologo //e:jscript "%~f0" > a.Log
  5. pause & exit
  6. @end
  7. var str = WSH.StdIn.ReadAll() + ':'
  8. var arr, reg = /Addresses:([\S\s]+?)(?=:)/g, map = [];
  9. while(arr = reg.exec(str)){
  10.     var re = /(\d+\.){3}\d+/g;
  11.     while(ar = re.exec(arr[1])){
  12.         if(!map[ar[0]]) { map[ar[0]]=1; WSH.Echo(ar[0]) };
  13.     }
  14. }
复制代码

作者: adslcool    时间: 2016-1-17 09:21

回复 2# WHY


    谢谢,非常感谢!




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2