ホームページ > php教程 > PHP源码 > PHP 执行 whois 操作的代码

PHP 执行 whois 操作的代码

PHP中文网
リリース: 2016-06-01 14:33:16
オリジナル
1262 人が閲覧しました

要获取指定IP地址的whois数据,可使用如下代码

1

2

3

4

5

6

7

8

9

10

11

12

<?php

/**

    Program to perform ip whois

    Silver Moon

    m00n.silv3r@gmail.com

*/

  

$ip = "74.65.112.23";

  

$whois = get_whois($ip);

  

echo "<pre class="brush:php;toolbar:false">$whois

"; /** Get the whois content of an ip by selecting the correct server */ function get_whois($ip) { $w = get_whois_from_server('whois.iana.org' , $ip); preg_match('@whois\.[\w\.]*@si' , $w , $data); $whois_server = $data[0]; //echo $whois_server; //now get actual whois data $whois_data = get_whois_from_server($whois_server , $ip); return $whois_data; } /** Get the whois result from a whois server return text */ function get_whois_from_server($server , $ip) { $data = ''; #Before connecting lets check whether server alive or not #Create the socket and connect $f = fsockopen($server, 43, $errno, $errstr, 3); //Open a new connection if(!$f) { return ''; } #Set the timeout limit for read if(!stream_set_timeout($f , 3)) { die('Unable to set set_timeout'); #Did this solve the problem ? } #Send the IP to the whois server if($f) { fputs($f, "$ip\r\n"); } /* Theory : stream_set_timeout must be set after a write and before a read for it to take effect on the read operation If it is set before the write then it will have no effect : http://in.php.net/stream_set_timeout */ //Set the timeout limit for read if(!stream_set_timeout($f , 3)) { die('Unable to stream_set_timeout'); #Did this solve the problem ? } //Set socket in non-blocking mode stream_set_blocking ($f, 0 ); //If connection still valid if($f) { while (!feof($f)) { $data .= fread($f , 128); } } //Now return the data return $data; }
ログイン後にコピー

执行结果

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

#

# Query terms are ambiguous.  The query is assumed to be:

#     "n 74.65.112.23"

#

# Use "?" to get help.

#

  

#

# The following results may also be obtained via:

# http://whois.arin.net/rest/nets;q=74.65.112.23?showDetails=true&showARIN=false&ext=netref2

#

  

NetRange:       74.64.0.0 - 74.79.255.255

CIDR:           74.64.0.0/12

OriginAS:

NetName:        RRNY

NetHandle:      NET-74-64-0-0-1

Parent:         NET-74-0-0-0-0

NetType:        Direct Allocation

RegDate:        2006-03-27

Updated:        2007-01-29

Ref:            http://whois.arin.net/rest/net/NET-74-64-0-0-1

  

OrgName:        Road Runner HoldCo LLC

OrgId:          RRNY

Address:        13820 Sunrise Valley Drive

City:           Herndon

StateProv:      VA

PostalCode:     20171

Country:        US

RegDate:        2000-09-28

Updated:        2011-07-06

Comment:        Allocations for this OrgID serve Road Runner residential customers out of the New York City, NY and Syracuse, NY RDCs.

Ref:            http://whois.arin.net/rest/org/RRNY

  

ReferralServer: rwhois://ipmt.rr.com:4321

  

OrgTechHandle: IPTEC-ARIN

OrgTechName:   IP Tech

OrgTechPhone:  +1-703-345-3416

OrgTechEmail:  abuse@rr.com

OrgTechRef:    http://whois.arin.net/rest/poc/IPTEC-ARIN

  

OrgAbuseHandle: ABUSE10-ARIN

OrgAbuseName:   Abuse

OrgAbusePhone:  +1-703-345-3416

OrgAbuseEmail:  abuse@rr.com

OrgAbuseRef:    http://whois.arin.net/rest/poc/ABUSE10-ARIN

  

#

# ARIN WHOIS data and services are subject to the Terms of Use

# available at: https://www.arin.net/whois_tou.html

#

ログイン後にコピー


関連ラベル:
php
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
PHP 拡張子 intl
から 1970-01-01 08:00:00
0
0
0
phpのデータ取得?
から 1970-01-01 08:00:00
0
0
0
PHP GET エラー レポート
から 1970-01-01 08:00:00
0
0
0
phpを上手に学ぶ方法
から 1970-01-01 08:00:00
0
0
0
人気のおすすめ
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート