Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get WAN IP from local Router Tested on NetGear DG834G ADSL WiFi Router
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/* | ||
// Program : Show NetGear ADSL Router WAN IP | ||
// Author : Ap.Muthu <apmuthu@usa.net> | ||
// Version : 1.0 | ||
// Release Date : 2017-09-19 | ||
// Tested on : NetGear DG834G | ||
// Example Usage : php.exe grab_router_ip.php | ||
*/ | ||
|
||
// Router credentials | ||
|
||
$rt_user = "admin"; | ||
$rt_pass = "MySecretRouterPassword"; | ||
$baseurl='192.168.0.1'; // router management interface LAN IP | ||
// $baseurl='www.routerlogin.com'; | ||
|
||
$url = "http://".$rt_user.":".$rt_pass."@".$baseurl."/setup.cgi?next_file=s_status.htm"; | ||
$a = file_get_contents($url); | ||
sleep(2); // seconds | ||
|
||
$b = explode('<td width="50%"><b>IP Address </b></td>', $a); | ||
$IP = get_inner_str($b[1]); | ||
echo $IP; | ||
|
||
function get_inner_str($str) { | ||
$strip_str = array('<strong>', '</strong>', "\t", "\r", "\n"); | ||
$str = str_replace($strip_str, '', $str); | ||
$x = explode('>', $str); | ||
$y = explode('<', $x[1]); | ||
return trim($y[0]); | ||
} | ||
|
||
?> |
011fb66
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of checking for WAN IP in external sites, use this script to locally parse it from the Router's Status page. Can use from local server and from CLI.