Skip to content

Instantly share code, notes, and snippets.

@luckman212
Last active March 8, 2026 05:34
Show Gist options
  • Select an option

  • Save luckman212/855f4f9243eb1b7a698d902ba4ed280e to your computer and use it in GitHub Desktop.

Select an option

Save luckman212/855f4f9243eb1b7a698d902ba4ed280e to your computer and use it in GitHub Desktop.
helper script to return interface IP on pfSense
#!/usr/bin/env php
<?php
require_once('interfaces.inc');
$ifaces = get_configured_interface_with_descr();
asort($ifaces);
$it = trim($argv[1]);
if (empty($it)) {
echo "specify an interface (BSD names also accepted e.g. ix0):\n";
foreach ($ifaces as $k => $v) {
printf("%-10s %s\n", $k, $v);
}
exit();
}
$realif = get_real_interface($it);
if (empty($realif)) {
die("interface '$it' does not exist\n");
}
$ip = get_interface_ip($realif) ?: get_interface_ipv6($realif);
echo $ip . PHP_EOL;
@luckman212
Copy link
Author

I updated the gist slightly since the original, it now correctly handles interfaces that ONLY have an IPv6 (e.g. GIF interfaces part of an HENET tunnel).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment