What you need?
– AirPort or AirPort extreme with snmp enabled
– Some Python knowledge (please don’t post questions about python, that’s for the python organization to help with)
1) Open AirPort Utility (/Applications/Utilities/AirPort Utility.app)
2) Click your AirPort or AirPort Extreme Device (ignore or cancel any automatic setups)
3) Click “Manual Setup” Lower left button
4) Click “Advanced”
5) Click “Logging and Statistics”
6) Check “Allow SNMP”
NOTE: You can also change the SNMP Community String, for security I highly recommend this unless your AirPort is behind a hardware or server firewall.
If you change the string your Python Script will need to be updated.
The Python Script:
import os import sys import subprocess CMD = 'snmpwalk -v 2c -c public 192.168.1.1 ipAdEntIfIndex' EXCLUDE_LIST = ['127', '192', '169', '10'] # exclude private ips def get_external_ip(): PIPE = subprocess.PIPE r = subprocess.Popen(CMD, shell=True, stdout=PIPE, stderr=PIPE) result = r.communicate() # import pdb; pdb.set_trace() for ip in result.split('\n'): if '=' in ip: parts = ip.split('=') ipaddress = ".".join(parts.split('.')[1:]) first_part = parts.split('.') if first_part not in EXCLUDE_LIST: return ipaddress if __name__=='__main__': print get_external_ip()
Once you have your external ip address printing to the shell. You can now do things like create a cron job on your server to push a text file to a public or private webserver for example. I recommend it be pushed to something you need a username and password to get in from the outside world. Maybe an ftp address that you can only access as admin.
Checking your command line:
snmpwalk -v 2c -c public 192.168.1.1 ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 3
IP-MIB::ipAdEntIfIndex.127.0.0.2 = INTEGER: 3
IP-MIB::ipAdEntIfIndex.169.254.38.226 = INTEGER: 5
IP-MIB::ipAdEntIfIndex.192.168.18.1 = INTEGER: 6
IP-MIB::ipAdEntIfIndex.184.108.40.206 = INTEGER: 5
The one I marked 220.127.116.11 would be your address most-likely. Remember, if you cant get this command to work the python script above is useless. So what ever you get working here you should put in the CMD =”” string in your python script. We skip over the 127/169/192/10 in our python script because these are private address. When we do this the remainder is your external ip address.
I could not find an easy way just yet using snmp protocol to get the external ip so this is the next best thing.
Please give it a try and post your comments!