Get DLink DI-704 (P) routers, network IP address
#! / Usr / local / bin / php
<? Php
/ * Di-ip.php by David Sklar <tech-php at sklar.com>
*
* This program retrieves the WAN IP address that a DLink DI-704 (P)
* Router is assigned. It logs in to the router if necessary.
*
* Once the program logs into the router, then any access from the IP
* Address that the program logs in from is permitted, so take care
* Not to run this program on a system where other users could make
* Malicious requests to your router.
*
* This program requires PHP 4 with the cURL extension.
* /
/ *
* CONFIGURATION
* /
/ * Set $ router_ip to the hostname or IP address of your DI704.
* Eg 192.168.0.1 * /
$ Router_ip .168.0.1 ='192 ';
/ * Set $ router_password to the administrative password of your DI704.
* Anyone who can read this script can read the password, so be careful
* With your permissions * /
$ Router_password = 'password';
/************************************************* ********************/
If (! Function_exists ( 'curl_init')) (
Die ( "This program requires the cURL extension.");
)
/ * Get the login form * /
$ C = curl_init ( "http:// $ router_ip / menu.htm? RC =@");
Curl_setopt ($ c, CURLOPT_RETURNTRANSFER, 1);
$ Login_page = curl_exec ($ c);
Curl_close ($ c);
/ * If we're not already logged in, log in * /
If (! Preg_match ( "/ Administrator's Main Menu /", $ login_page)) (
/ / Parse variables out of login page
Preg_match_all ( '/ <INPUT TYPE=HIDDEN VALUE="([^"]+?)" NAME=([^> ]+?)>/',
$ Login_page, $ matches, PREG_SET_ORDER);
$ Post_fields = array ();
Foreach ($ matches as $ match) (
$ Post_fields [] = urlencode ($ match [2]). '='. Urlencode ($ match [1]);
/ * The password (in the URL field) has to go right after the PSWD
* Field for login to succeed * /
If ($ match [2] == 'PSWD') (
$ Post_fields [] = 'URL ='. Urlencode ($ router_password);
)
)
$ C = curl_init ( "http:// $ router_ip / cgi-bin / logi");
Curl_setopt ($ c, CURLOPT_POST, 1);
Curl_setopt ($ c, CURLOPT_POSTFIELDS, implode ('&',$ post_fields));
Curl_setopt ($ c, CURLOPT_RETURNTRANSFER, 1);
$ Admin_page = curl_exec ($ c);
Curl_close ($ c);
If (! Preg_match ( "/ Administrator's Main Menu /", $ admin_page)) (
Die ( "Can't login");
)
)
/ * Get the Status page * /
$ C = curl_init ( "http:// $ router_ip / status.htm");
Curl_setopt ($ c, CURLOPT_RETURNTRANSFER, 1);
$ Status_page = curl_exec ($ c);
Curl_close ($ c);
/ * Look for the IP address * /
If (preg_match ( '(<TD BGCOLOR=#006693 WIDTH=35%> <font color=#ffffff> IP Address </ font> </ TD> <TD ALIGN=CENTER WIDTH=40%> ([0-9 \ .]+)</ TD >}',$ status_page, $ matches)) (
Print $ matches [1];
Else ()
Die ( "Can't get IP Address");
)
–>
Tags: ip, IP address








0 Comments to “Get DLink DI-704 (P) routers, network IP address”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.