-
Notifications
You must be signed in to change notification settings - Fork 11
/
Natget.class.php
63 lines (61 loc) · 1.53 KB
/
Natget.class.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
53
54
55
56
57
58
59
60
61
62
63
<?php
// vim: set ai ts=4 sw=4 ft=php:
namespace FreePBX\modules\Firewall;
class Natget {
/**
* Get Visible IP by querying freepbx.org
* @return array Status of result
*/
public function getVisibleIP() {
$ip = false;
try {
$pest = new \PestXML("http://myip.freepbx.org:5060");
$thing = $pest->get('/whatismyip.php');
} catch(\Exception $e) {
return false;
}
if(!empty($thing->ipaddress) && filter_var((string)$thing->ipaddress, FILTER_VALIDATE_IP)) {
return (string)$thing->ipaddress;
} else {
return false;
}
}
/**
* Get Local routes
* @return array Array of routes
*/
public function getRoutes() {
// Return a list of routes the machine knows about.
$route = fpbx_which('route');
if(empty($route)) {
return array();
}
exec("$route -nv",$output,$retcode);
if($retcode != 0 || empty($output)) {
return array();
}
// Drop the first two lines, which are just headers..
array_shift($output);
array_shift($output);
// Now loop through whatever's left
$routes = array();
foreach ($output as $line) {
$arr = preg_split('/\s+/', $line);
if(count($arr) < 3) {
//some strange value we dont understand
continue;
}
if ($arr[2] == "0.0.0.0" || $arr[2] == "255.255.255.255") {
// Don't care about default or host routes
continue;
}
if (substr($arr[0], 0, 7) == "169.254") {
// Ignore ipv4 link-local addresses. See RFC3927
continue;
}
$cidr = 32-log((ip2long($arr[2])^4294967295)+1,2);
$routes[] = array($arr[0], $cidr);
}
return $routes;
}
}