How to query whois information in php

Source: Internet
Author: User

How to query whois information in php

This example describes how to query whois information in php. Share it with you for your reference. The details are as follows:

Php is used to query the whois information list.

?

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

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

Function whois_query ($ domain ){

// Fix the domain name:

$ Domain = strtolower (trim ($ domain ));

$ Domain = preg_replace ('/^ http: \\// I', '', $ domain );

$ Domain = preg_replace ('/^ www \./I', '', $ domain );

$ Domain = explode ('/', $ domain );

$ Domain = trim ($ domain [0]);

// Split the TLD from domain name

$ _ Domain = explode ('.', $ domain );

$ Lst = count ($ _ domain)-1;

$ Ext = $ _ domain [$ lst];

// You find resources and lists

// Like these on wikipedia:

//

// Http://de.wikipedia.org/wiki/Whois

//

$ Servers = array (

"Biz" => "whois. neulevel. biz ",

"Com" => "whois.internic.net ",

"Us" => "whois. nic. us ",

"Coop" => "whois. nic. coop ",

"Info" => "whois.nic.info ",

"Name" => "whois. nic. name ",

"Net" => "whois.internic.net ",

"Gov" => "whois.nic.gov ",

"Edu" => "whois.internic.net ",

"Mil" => "rs.internic.net ",

"Int" => "whois.iana.org ",

"Ac" => "whois. nic. ac ",

"AE" => "whois. uaenic. AE ",

"At" => "whois.ripe.net ",

"Au" => "whois.aunic.net ",

"Be" => "whois. dns. be ",

"Bg" => "whois.ripe.net ",

"Br" => "whois.registro.br ",

"Bz" => "whois. belizenic. bz ",

"Ca" => "whois. cira. ca ",

"Cc" => "whois. nic. cc ",

"Ch" => "whois. nic. ch ",

"Cl" => "whois. nic. cl ",

"Cn" => "whois.cnnic.net.cn ",

"Cz" => "whois. nic. cz ",

"De" => "whois.nic.de ",

"Fr" => "whois. nic. fr ",

"Hu" => "whois. nic. hu ",

"Ie" => "whois. domainregistry. ie ",

"Il" => "whois.isoc.org. il ",

"In" => "whois. ncst. ernet. in ",

"Ir" => "whois. nic. ir ",

"Mc" => "whois.ripe.net ",

"To" => "whois. tonic. ",

"TV" => "whois. TV ",

"Ru" => "whois.ripn.net ",

"Org" => "whois.pir.org ",

"Aero" => "whois. information. aero ",

"Nl" => "whais. domain-registry.nl"

);

If (! Isset ($ servers [$ ext]) {

Die ('error: No matching nic server found! ');

}

$ Nic_server = $ servers [$ ext];

$ Output = '';

// Connect to whois server:

If ($ conn = fsockopen ($ nic_server, 43 )){

Fputs ($ conn, $ domain. "\ r \ n ");

While (! Feof ($ conn )){

$ Output. = fgets ($ conn, 128 );

}

Fclose ($ conn );

}

Else {die ('error: cocould not connect to '. $ nic_server .'! ');}

Return $ output;

}

// Some example queries:

Print whois_query ('jonasjohn. de ');

Print whois_query ('example. com ');

Print whois_query ('example. org ');

I hope this article will help you with php programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.