× Introducing the Orbi 970 Series Mesh System with WiFi 7 technology. For more information visit the NETGEAR Press Room.
Nighthawk M6 Pro Unlocked Hotspot 5G mmWave
Reply

Re: Read status of LM1200

Fiddlin
Tutor

Read status of LM1200

Does anyone know of a way to read the status of an LM1200 without watching the web page?  I would like to use anything similar to SNMP to just get a text reading of connection status, cell signal level, session data usage and data/days remaining.

Message 1 of 7

Accepted Solutions
JohnPeng
NETGEAR Expert

Re: Read status of LM1200

You can try to log in to WebUI as admin and capture the model.json log. It will present the info you require. If you need any help on reading the logs, I can help.

 

- Logon to the webui (http://192.168.1.1 ) as an administrator
- Navigate to URL http://192.168.1.1/model.json via the same browser window
- Capture the results (by selecting all + copy) and send it back

 

Hope this helps.

 

Thanks

 

View solution in original post

Message 2 of 7

All Replies
JohnPeng
NETGEAR Expert

Re: Read status of LM1200

You can try to log in to WebUI as admin and capture the model.json log. It will present the info you require. If you need any help on reading the logs, I can help.

 

- Logon to the webui (http://192.168.1.1 ) as an administrator
- Navigate to URL http://192.168.1.1/model.json via the same browser window
- Capture the results (by selecting all + copy) and send it back

 

Hope this helps.

 

Thanks

 

Message 2 of 7
Fiddlin
Tutor

Re: Read status of LM1200

Thanks John!  There is a ton of data in there.  That should work great for building a small status display app.

Message 3 of 7
Fiddlin
Tutor

Re: Read status of LM1200

Well, the data is in there, but so far, I have not figured out how to get the full (logged in version) model.json data with a script rather than just getting it with a browser.  Do you have any suggestions?

Message 4 of 7
JohnPeng
NETGEAR Expert

Re: Read status of LM1200


@Fiddlin wrote:

Well, the data is in there, but so far, I have not figured out how to get the full (logged in version) model.json data with a script rather than just getting it with a browser.  Do you have any suggestions?


I am not a programmer, but can you check the following link to see whether this is helpful?

 

https://stackoverflow.com/questions/34393353/login-to-a-website-using-script

 

You can run one script to get the model.json periodically and run another one to parse the data you need.

 

Thanks

 

Message 5 of 7
Fiddlin
Tutor

Re: Read status of LM1200

I did finally get it working.  I was hoping to just use javascript in a local HTML file, but I ran into a ton of CORS (cross-origin request) errors.  I got it working by using PHP and its cURL library.  It is nice being able to see my GB/day remaining so I can maintain my data-rationing.

 

Thank you for the help.

Message 6 of 7
Fiddlin
Tutor

Re: Read status of LM1200

I don't know if anyone will be interested, but here is my hacked up code for pulling the session details from my LM1200.

 

I plan to have this script run on my web server and build a pretty graph that will be saved as HTML for my other computers to display so they are not all requesting updates directly from the LM1200.

 

<?php
$ipaddress = "192.168.5.1";
$cookiefile = "cookie.txt";
$password = "password";


function InitializeCurl($cookiefile) {
	$curl = curl_init();
	curl_setopt($curl,CURLOPT_COOKIEJAR,$cookiefile); //file for saving cookie data
	curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false); //this is local traffic - don't bother with SSL verification
	curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false); //this is local traffic - don't bother with SSL verification
	curl_setopt($curl,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
	curl_setopt($curl,CURLOPT_RETURNTRANSFER,true); //always want to capture result to string
	curl_setopt($curl,CURLOPT_HEADER,false); //leave headers out of result string
	return($curl);
}


function GetToken($curl,$ipaddress) {
	$url = "http://$ipaddress";

	curl_setopt($curl,CURLOPT_URL,$url);
	curl_setopt($curl,CURLOPT_FOLLOWLOCATION,true); //Let LM1200 forward to /index.html

	$result = curl_exec($curl);

	//Extract token from result
	$n = preg_match('/\"token\" value=\"([^\"]+)/',$result,$match);
	if ($n>0) { $token = $match[1]; } else { $token = ""; }
	return($token);
}


function DoLogin($curl,$ipaddress,$token,$password) {

	$data = 'token=' . $token . '&ok_redirect=%2Findex.html&err_redirect=%2Findex.html&session.password=' . $password;

	curl_setopt($curl,CURLOPT_URL,"http://{$ipaddress}/Forms/config");
	curl_setopt($curl,CURLOPT_POST,true);
	curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
	curl_setopt($curl,CURLOPT_REFERER,"http://{$ipaddress}/index.html");
	curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
	curl_setopt($curl,CURLOPT_FOLLOWLOCATION,false);
	curl_setopt($curl,CURLOPT_HTTPHEADER,array( //Simulate headers captured from chrome developer mode
		'Content-Type: application/x-www-form-urlencoded'
		,'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
		,'Accept-Encoding: gzip, deflate'
		,'Accept-Language: en-US,en;q=0.9'
		,'Origin: http://' . $ipaddress
		));

	$result = curl_exec($curl); //discard results - this will set the session as logged in
}


function GetJson($curl,$ipaddress,$token) {
	curl_setopt($curl,CURLOPT_FOLLOWLOCATION,false); //don't follow redirects for json calls
	curl_setopt($curl,CURLOPT_HTTPHEADER,array( //simulate headers captured from chrome developer mode
		'Accept: */*'
		,'Accept-Encoding: gzip, deflate'
		,'Accept-Language: en-US,en;q=0.9'
		,'Origin: http://' . $ipaddress
	));

	curl_setopt($curl,CURLOPT_POST,false); //force cURL back to GET
	curl_setopt($curl,CURLOPT_POSTFIELDS,''); //force cURL back to GET
	curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'GET'); //force cURL back to GET

	$randomnum = rand(0,65535); //my guess is that this is a random number to prevent caching?
	curl_setopt($curl,CURLOPT_URL,"http://{$ipaddress}/api/model.json?internalapi=1&x={$randomnum}");

	$result = curl_exec($curl);
	$json = json_decode($result);
	
	return($json);
}


function ShowStatus($json) {
	echo "\n\n";
	echo "IP: {$json->wwan->IP}\n";
	echo "Next billing date: " . strftime("%Y-%m-%d %H:%M:%S",$json->wwan->dataUsage->generic->nextBillingDate) . "\n";
	echo "Billing cycle remainder: " . number_format($json->wwan->dataUsage->generic->billingCycleRemainder) . " seconds\n";
	echo "-----\n";
	echo "Data transferred: " . number_format($json->wwan->dataUsage->generic->dataTransferred) . "\n";
	echo "Billing cycle limit: " . number_format($json->wwan->dataUsage->generic->billingCycleLimit) . "\n";
	echo "-----\n";
	echo "Session duration: " . number_format($json->wwan->sessDuration) . " seconds\n";
	echo "Session start time: " . strftime("%Y-%m-%d %H:%M:%S",$json->wwan->sessStartTime) . "\n";
	echo "Session transferred: " . number_format($json->wwan->dataTransferred) . "\n";
	echo "Session Rx: " . number_format($json->wwan->dataTransferredRx) . "\n";
	echo "Session Tx: " . number_format($json->wwan->dataTransferredTx) . "\n";

	$dataremaining = $json->wwan->dataUsage->generic->billingCycleLimit - $json->wwan->dataUsage->generic->dataTransferred;
	$daysremaining = $json->wwan->dataUsage->generic->billingCycleRemainder / 24 / 60 / 60;
	$dataperday = $dataremaining / $daysremaining;
	echo "Data per day left: $dataperday\n";

	$gigperday = $dataperday / 1024 / 1024 / 1024;
	printf("GB/day left: %3.3f\n",$gigperday);
}


$curl = InitializeCurl($cookiefile);
$token = GetToken($curl,$ipaddress);
DoLogin($curl,$ipaddress,$token,$password);

while (true) {
	$json = GetJson($curl,$ipaddress,$token);
	ShowStatus($json);
	sleep(60);
}

curl_close($curl);
?>

 

Message 7 of 7
Top Contributors
Discussion stats
  • 6 replies
  • 2059 views
  • 2 kudos
  • 2 in conversation
Announcements

Orbi WiFi 7