]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - misc/ip-whois-misc.php
make table headers blue again
[irc/unrealircd/unrealircd-webpanel.git] / misc / ip-whois-misc.php
1 <?php
2
3 function get_ip_whois($ip)
4 {
5 $w = get_ip_whois_from_server('whois.iana.org' , $ip);
6
7 preg_match("#whois:\s*([\w.]*)#si" , $w , $data);
8
9 $whois_server = $data[1];
10 $whois_data = get_ip_whois_from_server($whois_server , $ip);
11
12 return $whois_data;
13 }
14
15 function get_ip_whois_from_server($server , $ip)
16 {
17 $data = '';
18 $server = trim($server);
19
20 if(!strlen($server))
21 {
22 return Message::Fail("Lookup failed: Could not find appropriate WHOIS server. Maybe you typed an incorrect IP?");
23 }
24
25 $f = fsockopen($server, 43, $errno, $errstr, 3); //Open a new connection
26
27 if (!$f)
28 {
29 Message::Fail("Lookup failed: Could not open socket");
30 }
31
32 // Set the timeout limit for read
33 if (!stream_set_timeout($f , 3))
34 {
35 return Message::Fail("Lookup failed: Connection timed out");
36 }
37
38 // Send the IP to the whois server
39 if ($f)
40 {
41 $message = $ip . "\r\n";
42 fputs($f, $message);
43 }
44
45
46 if( !stream_set_timeout($f , 3))
47 {
48 return Message::Fail("Lookup failed: Unable to stream_set_timeout");
49 }
50
51 // Set socket in non-blocking mode
52 stream_set_blocking ($f, 0 );
53
54 // If connection still valid
55 if($f)
56 {
57 while (!feof($f))
58 {
59 $data .= fread($f , 128);
60 }
61 }
62
63 // Now return the data
64 return $data;
65 }
66
67 function generate_ip_whois_table($data)
68 {
69 ?>
70 <div class="container-xl">
71 <table class="table table-responsive-xl caption-top table-hover">
72 <tbody>
73 <?php
74 foreach ($data as $d)
75 foreach ($d as $key => $val)
76 {
77 ?>
78 <tr><th><?php echo htmlspecialchars($key); ?></th><td>
79 <?php
80 if (filter_var($val, FILTER_VALIDATE_EMAIL))
81 $val = "<a href=\"mailto:$val\">$val</a>";
82 echo "<code>$val</code>";
83 ?>
84 </td></tr>
85 <?php
86 }
87 ?>
88 </tbody>
89 </table>
90 </div>
91 <?php
92 }