-
Notifications
You must be signed in to change notification settings - Fork 1
/
dcc-funct.php
52 lines (44 loc) · 990 Bytes
/
dcc-funct.php
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
<?php
function get_ip() {
static $ip;
$matches='';
if(!isset($ip) or empty($ip)) {
$data=trim(file_get_contents('http://checkip.dyndns.org'));
preg_match('!^<html><head><title>Current IP Check</title></head><body>Current IP Address: ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})</body></html>$!i',$data,$matches);
$ip=$matches[1];
}
return $ip;
}
/* Functions handling packets transfers for DCC */
function htons($num)
{
$num = decbin($num);
while(strlen($num) < 8*4)
{
$num = '0'.$num;
}
$bytes = array();
while(strlen($num) > 8)
{
$bytes[] = substr($num, 0, 8);
$num = substr($num, 8);
}
$bytes[] = $num;
return chr(bindec($bytes[0])).chr(bindec($bytes[1])).chr(bindec($bytes[2])).chr(bindec($bytes[3]));
}
function ntohs($num)
{
$ret = 0;
for($i=0; $i<4; $i++)
{
$x = ord($num{$i});
$x = decbin($x);
while (strlen($x) < 8)
{
$x = '0'.$x;
}
$ret .= $x;
}
return bindec($ret);
}
?>