Created
April 25, 2021 14:49
-
-
Save AaronC81/ac07a59afa8a90a97590fe8972dd92aa to your computer and use it in GitHub Desktop.
Get public IP address of TP-Link router, for dynamic DNS
This file contains 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
# Fetches the public IP of a TP-Link Archer MR400 router. | |
# For some reason, this wasn't the same as you see from a _device_ connected to | |
# the router, so typical FreeDNS updates which use the IP of the device | |
# requesting the update weren't working. | |
# You must install the 'snmp' gem and enable SNMP in the router settings. | |
require 'snmp' | |
# The local IP address of the router | |
GATEWAY_IP = "192.168.1.1" | |
# This is "ipAddrEntry", found with iReasoning | |
ip_addr_entry_oid = SNMP::ObjectId.new("1.3.6.1.2.1.4.20.1") | |
# Connect to the router over SNMP | |
manager = SNMP::Manager.new(host: GATEWAY_IP) | |
# Grab public IP object | |
ip_obj = manager.get_next(ip_addr_entry_oid).varbind_list[0] | |
# Get IP, as a dotted string | |
ip = ip_obj.value.to_s | |
puts ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for sharing -- this is exactly what i need :)