Last active
March 8, 2026 05:34
-
-
Save luckman212/855f4f9243eb1b7a698d902ba4ed280e to your computer and use it in GitHub Desktop.
helper script to return interface IP on pfSense
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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; |
Author
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
Instructions
Now, you can query for the IP of any interface remotely via
tip: running without any argument will list configured interfaces
Examples