Board logo

标题: [文本处理] 如何获取nslookup命令返回结果中的IPv6地址? [打印本页]

作者: recoba    时间: 2016-4-8 20:41     标题: 如何获取nslookup命令返回结果中的IPv6地址?

本帖最后由 pcl_test 于 2016-4-8 21:33 编辑

请问  想用nslookup 指定DNS(74.82.42.42)    批处理A文件获得ipv6地址       生成B文件
nslookup -qt=AAAA www.google.com 74.82.42.42
像这样


A文件  www.google.com
获得
B文件  2607:f8b0:4007:807::200e    www.google.com

这个批处理要怎么写啊?
作者: ivor    时间: 2016-4-8 22:37

本帖最后由 ivor 于 2016-4-8 22:41 编辑
  1. @echo off&setlocal ENABLEDELAYEDEXPANSION
  2. (for /f "delims=" %%i in (a.txt) do (
  3. for /f "tokens=1,2" %%j in ('nslookup -qt^=AAAA %%i 74.82.42.42') do (
  4. set last=%%k
  5. )
  6. echo !last! %%i
  7. ))>b.txt
  8. pause
复制代码
回复 1# recoba
作者: codegay    时间: 2016-4-9 14:26

  1. """
  2. python获取DNS查询结果.py
  3. http://bbs.bathome.net/thread-39978-1-1.html
  4. 2016年4月9日 10:08:16 codegay
  5. """
  6. import re
  7. import subprocess
  8. host="www.google.com"
  9. txt=subprocess.getoutput("nslookup -qt=AAAA www.google.com 223.5.5.5")
  10. print(txt)
  11. result=re.findall(r"""Address:  ((?:\w*:){5}\w*)""",txt)[0]
  12. print("匹配结果:",result)
  13. with open("result.txt","w+") as f:
  14.     f.write(result+"\t"+host+"\n")
  15. """
  16. 非权威应答:
  17. 服务器:  public1.alidns.com
  18. Address:  223.5.5.5
  19. 名称:    www.google.com
  20. Address:  2404:6800:4005:801::2004
  21. 匹配结果: 2404:6800:4005:801::2004
  22. [Finished in 0.2s]
  23. """
复制代码

作者: recoba    时间: 2016-4-9 15:51

感谢  好心人真多啊




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