Skip to content

Commit

Permalink
grab_router_ip.php script added
Browse files Browse the repository at this point in the history
Get WAN IP from local Router
Tested on NetGear DG834G ADSL WiFi Router
  • Loading branch information
apmuthu committed Sep 19, 2017
1 parent d0a3123 commit 011fb66
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions grab_router_ip.php
@@ -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]);
}

?>

1 comment on commit 011fb66

@apmuthu
Copy link
Owner Author

@apmuthu apmuthu commented on 011fb66 Sep 19, 2017

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.

ngauth

Please sign in to comment.