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

luckman212 commented Mar 7, 2026

from: https://forum.netgate.com/topic/200305/read-the-public-ip

Instructions

  1. ssh to your pfSense
  2. select option 8 (Shell)
  3. paste the commands below:
mkdir -p /root/bin
curl -Lso /root/bin/if_ip.php https://gist.github.com/luckman212/855f4f9243eb1b7a698d902ba4ed280e/raw
chmod +x /root/bin/if_ip.php

Now, you can query for the IP of any interface remotely via

ssh <pfsense-ip> /root/bin/if_ip.php <friendlyname|bsd_name>

tip: running without any argument will list configured interfaces

Examples

# ssh r1.lan /root/bin/if_ip.php wan
180.70.60.23

# ssh r1.lan /root/bin/if_ip.php igb0
192.168.10.1

@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