Skip to content

Instantly share code, notes, and snippets.

@kanazux
Created October 19, 2017 19:04
Show Gist options
  • Save kanazux/5e394bb019d39e30ef483889bbc3f363 to your computer and use it in GitHub Desktop.
Save kanazux/5e394bb019d39e30ef483889bbc3f363 to your computer and use it in GitHub Desktop.
get interface ip by the default gateway on pfsense
<?php
require_once("interfaces.inc");
require_once("gwlb.inc");
$i = get_interfaces_with_gateway();
$a = shell_exec("netstat -rn | grep -i default | sed -r 's/(.*\ )([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})(.*)/\\2/p' | sort -u");
$gw_arr = return_gateways_array();
foreach($gw_arr as $gw)
if($gw['gateway'] == trim($a))
print get_interface_ip($gw['friendlyiface']);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment