我必须使用dig
来获取域名的IP。我可以运行dig
并获得如下输出(使用www.google.no作为示例):
1
2 ; <<>> DiG 9.10.3 <<>> www.google.no A
3 ;; global options: +cmd
4 ;; Got answer:
5 ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2264
6 ;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1
7
8 ;; OPT PSEUDOSECTION:
9 ; EDNS: version: 0, flags:; udp: 1280
10 ;; QUESTION SECTION:
11 ;www.google.no. IN A
12
13 ;; ANSWER SECTION:
14 www.google.no. 129 IN A 74.125.232.111
15 www.google.no. 129 IN A 74.125.232.119
16 www.google.no. 129 IN A 74.125.232.127
17 www.google.no. 129 IN A 74.125.232.120
18
19 ;; Query time: 0 msec
20 ;; SERVER: 10.69.201.10#53(10.69.201.10)
21 ;; WHEN: Tue Jan 19 13:37:41 Vest-Europa (normaltid) 2016
22 ;; MSG SIZE rcvd: 106
如何从上述输出的第14-17行获取IP地址?
答案 0 :(得分:1)
我设法解决了这个问题 - 将+short
添加到dig
命令的末尾:
答案 1 :(得分:0)
您可以使用正则表达式轻松解析它。
$text = "return of dig";
$regex = "/[a-z\.]+\s*[0-9]+\s*IN\s*A\s*(([0-9]+.){4})/g";
preg_match_all($text, $regex, $results);
var_dump($results);