Recommended Posts

So, if like me you've got BT's internet and have to use an echolife HG612 gateway and also run a server, you want your DNS to always be pointing to your IP even if it changes (Despite having a UPS, sometimes the line here drops for no reason and the IP changes).

So, I thought the ideal solution would be to just get the IP direct from the gateway itself! Now, I've reflashed my gateway to the stock echolife firmware so I have access to the web interface panel which this needs! Also note that it does some pretty lame output with the headers too. Anyway, this WILL need to be modified to work with your gateway I think, it works for mine with the specified WAN interface name!

Anyway, this in in PHP and uses CURL (I dislike CURL immensly but for some reason it wasn't liking my fsockopen and kept returning a piece of javascript code)

<?PHP
/*
	   Echolife WAN IP Retriever
	   Version 0.5
	   Created by n_K, 2012
	   Modify and use this script how you please.
*/
function DoCurl($URL, $POST = null, $Cookies = null)
{
		//Get a page using CURL.
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, $URL);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_TIMEOUT, 6);
		curl_setopt($curl, CURLOPT_USERAGENT, 'EcholifeIPUpdater/0.5 (n_K)');
		curl_setopt($curl, CURLOPT_HEADER, true);
		if (!is_null($POST))
		{
				curl_setopt($curl, CURLOPT_POST, true);
				if (strlen($POST) > 2)
				{
						curl_setopt($curl, CURLOPT_POSTFIELDS, $POST);
				}
		}
		else
		{
				curl_setopt($curl, CURLOPT_POST, false);
		}
		if (!is_null($Cookies))
		{
				curl_setopt($curl, CURLOPT_COOKIE, $Cookies);
		}

		$result = curl_exec($curl);
		curl_close($curl);
		return $result;
}

function CurlCookies($Data)
{
		//Extract cookies from received data. (MODIFIED FOR USE WITH ECHOLIFE ONLY!)
		$Matches = preg_split('/Set-cookie:(.*?);/', $Data, -1, PREG_SPLIT_DELIM_CAPTURE);
		$i = 0;
		$Cookies = '';
		while ($i < count($Matches))
		{
				if ($i%2 == 1)
				{
						//Odd number-index!
						$Cookies .= $Matches[$i].'; ';
				}
				++$i;
		}
		$Cookies = substr($Cookies, 0, strlen($Cookies)-1);
		return $Cookies;
}

//Login to the modem as unpriviledged user and get the cookies
$Login = DoCurl('http://192.168.1.1/html/login.cgi?Username='./* PUT YOUR ECHOLIFE GATEWAY LOGIN USERNAME HERE */.'&Password='.rawurlencode(base64_encode(/* PUT YOUR ECHOLIFE GATEWAY PASSWORD HERE */)).'&Language=0&RequestFile=html/status/internetstatus.gz.html', 'a', 'Cookie=LoginTimes=0:LoginOverTime=0; FirstMenu=Admin_0; SecondMenu=Admin_0_0; ThirdMenu=Admin_0_0_0; sessionID=2222224564789011; Language=English');
$Cookies = CurlCookies($Login);

//Get the internet status page
$BigData = explode("\n", DoCurl('http://192.168.1.1/html/status/internetstatus.asp', null, $Cookies));
if (count($BigData) > 3)
{
		//Looks like we have some data to parse!
		foreach ($BigData as $ThisLine)
		{
				/* CHANGE YOUR GATEWAY INTERFACE BELOW TO WHAT IS DISPLAYED ON WAN PAGE 'WanPPP2' IN MY CASE */
				if (substr($ThisLine, 0, 14) == 'var WanPPP2 = ')
				{
						//We have it!
						$Data = $ThisLine;
						break;
				}
		}

		if (strlen($Data) > 5)
		{
				//Got it!
				/* CHANGE YOUR GATEWAY INTERFACE BELOW TO WHAT IS DISPLAYED ON WAN PAGE 'ptm1.101' IN MY CASE */
				$Data = explode(',', explode('ptm1.101",', $Data)[1]);
				/*
						0 = connected/not
						1 = IP
						2 = DNS servers
						3 = ?
						4 = ?
				*/
				if ($Data[0] == '"Connected"')
				{
						//Yay! We've got the IP!
						$IP = substr($Data[1], 1, (strlen($Data[1])-2));
						if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $IP, $BB) > 0)
						{
								//IP is in right format too!

/* PUT YOUR IP UPDATING/USING CODE HERE! */
						}
						else
						{
								//No valid IP found
						}
				}
				else
				{
						//Error, no connection!
				}
		}
		else
		{
				//Couldn't find WAN interface
		}
}
else
{
		//No data returned
}
?>

So there you go, maybe it'll be of use to someone!

Link to comment
https://www.neowin.net/forum/topic/1108769-getting-echolife-gateway-ip/
Share on other sites

"So, I thought the ideal solution would be to just get the IP direct from the gateway itself!"

Why is that? Why can you not just hit the update page of your dynamic dns provider from your server and have it use your source IP. This seems much more robust a solution than access your routers status page. And then you have to put in your code anyway to update your dyndns provider

/* PUT YOUR IP UPDATING/USING CODE HERE! */

Seems lot of extra steps when you could just hit the provider page and have it use the source IP your coming from as your update - this is how most of them work.

The servers have static IPs addressed as 192.168.1.x, and yes I could hit sites likes whatismyip.net and use them but there's no guarantee they're right, plus they might change the page layout/system like whatismyip.org which now has an image to stop you using it to get your IP in scripts.

Plus I don't have a dynamic IP providers, I've got 2 domains with DNS control on 123-reg (which was also a complete pain to get working via CLI).

And the last reason is that I've got multiple WAN connections, so the server that runs this script has internet out a different IP and interface than what the gateway is on so the IPs wouldn't be right anyway.

Who said anything about using whatmyip?

So your dns is hosted on 123 reg? I don't see anything on their site about adjustment of TTLs -- so even if your IP changes, what is the TTL if its anything more than a say a few minutes. Your server is going to be down for quite some time any any sort of IP change on your end. Not a optimal sort of setup at all, I would host your dns from a site that provides for dynamic updates and low ttls on the records.

No **** your servers behind your router are most likely going to have private ips -- if they were public it would be very unlikely that you were on a dynamic IP in the first place.

"so the server that runs this script has internet out a different IP and interface than what the gateway is on so the IPs wouldn't be right anyway."

Well that seems again like a pretty messed up way to do it ;) Why not just run the script on the server itself, or route the traffic to your update so it goes out the connection your servers would be accepting traffic on.

A simple http string quite often can update the IP that changes -- so for example on zoneedit with wget

wget -O - --http-user=username --http-passwd=password 'http://dynamic.zoneedit.com/auth/dynamic.html?host=www.mydomain.com'

There you go your IP is updated using the source IP you came from - run this on the server your wanting to point to, and shazam your IP would be updated. This looks a lot simpler than your convoluted method to me.

Also any dns provider that supports dynamic updates would most likely have a client you could just run on the service. zoneedit for example has clients that run on windows, linux and mac. Also have cross platform support with java, perl and python.

Seems to me your wasting a lot of time reinventing the wheel without spending a couple of minutes looking to see how it can be done easier, faster and better.

Signing up to a dyndns service would mean I'd have to move my domains and pay extra (dyndns charge more than static DNS providers).

123-reg does it pretty secure, i.e. it's SSL ONLY and it's all ajax so you've got to go through a lot of tosh to get various pieces of information you need to change things.

Short TTL is crap anyway, get a short TTL and suddenly everywhere stops accepting your emails. Although 123-reg has TTL of 24 hours I've found if I clear my DNS cache it and retry it'll update without 10 minutes.

OK just a random problem that I found out about earlier, the refurbished PC we got had it's network card set to jumbo packets and I was wondering why hotmail just refused to load and only some pieces of data came through, very slowly, not sure if it's a hotmail issue or an issue with this modem or what but disabling jumbo frames fixed it completely, so just a warning to people :)

This topic is now closed to further replies.
  • Posts

    • BleachBit 6.0.1 Beta by Razvan Serea When your computer is getting full, BleachBit quickly frees disk space. When your information is only your business, BleachBit guards your privacy. With BleachBit you can free cache, delete cookies, clear Internet history, shred temporary files, delete logs, and discard junk you didn't know was there. Designed for Linux and Windows systems, it wipes clean thousands of applications including Firefox, Microsoft Edge, Google Chrome, Opera, Safari, and more. Beyond simply deleting files, BleachBit includes advanced features such as shredding files to prevent recovery, wiping free disk space to hide traces of files deleted by other applications, and vacuuming Firefox to make it faster. Better than free, BleachBit is open source. BleachBit has many useful features: Delete your private files so completely that "even God can't read them" according to South Carolina Representative Trey Gowdy. Simple operation: read the descriptions, check the boxes you want, click preview, and click delete. Multi-platform: Linux and Windows Free of charge and no money trail Free to share, learn, and modify (open source) No adware, spyware, malware, browser toolbars, or "value-added software" Translated to 64 languages besides American English Shred files to hide their contents and prevent data recovery Shred any file (such as a spreadsheet on your desktop) Overwrite free disk space to hide previously deleted files Portable app for Windows: run without installation Command line interface for scripting and automation CleanerML allows anyone to write a new cleaner using XML Automatically import and update winapp2.ini cleaner files (a separate download) giving Windows users access to 2500+ additional cleaners Frequent software updates with new features Going beyond standard deletion of files, BleachBit has several advanced cleaners: Clear the memory and swap on Linux Delete broken shortcuts on Linux Delete the Firefox URL history without deleting the whole file—with optional shredding Delete Linux localizations: delete languages you don't use. More powerful than localepurge and available on more Linux distributions. Clean APT for Debian, Ubuntu, Kubuntu, Xubuntu, and Linux Mint Find widely-scattered junk such as Thumbs.db and .DS_Store files. Execute yum clean for CentOS, Fedora, and Red Hat to remove cached package data Delete Windows registry keys—often where MRU (most recently used) lists are stored Delete the OpenOffice.org recent documents list without deleting the whole Common.xcu file Overwrite free disk space to hide previously files Vacuum Firefox, Google Chrome, Liferea, Thunderbird, and Yum databases: shrink files without removing data to save space and improve speed Surgically remove private information from .ini and JSON configuration files and SQLite3 databases without deleting the whole file Overwrite data in SQLite3 before deleting it to prevent recovery (optional) BleachBit 6.0.1 Beta release notes: BleachBit 6.0.1 beta is now available for testing. This maintenance-focused release includes bug fixes, updated translations, and a range of safe enhancements. This release fixes a Windows security issue that could allow arbitrary file deletion during privileged cleaning (reported by Zeze with TeamT5). It also adds new cleaners (including a DNS cache cleaner, Claude Code, and Visual Studio Code forks), support for multiple Chrome and Edge profiles, new deep scan options for developer directories like node_modules and venv, and safer, faster file shredding. All Platforms Added cleaners for Claude Code, DNS cache, and many Visual Studio Code forks. Added support for multiple Chrome and Edge profiles. Chrome can now clean downloaded AI models. Deep Scan can optionally remove venv, __pycache__, node_modules, and .angular directories. Deep Scan is faster by skipping directories on the keep list. File shredding is safer, faster, and leaves fewer recoverable traces. Improved handling of cookies, symlinks, Unicode filenames, external processes, and configuration files. Improved Expert Mode warnings and long warning dialogs. Fixed crashes related to cleaner detection, invalid Unicode, and malformed cleaner data. Clipboard is now cleared automatically after shredding files via paste operations. Linux Added AppImage support. Added cleaners for Visual Studio Code, Codeium, Librewolf (.deb), Transmission (Flatpak), and Profanity. Improved Linux trash detection, including Snap-installed applications and mounted drives. Fixed Wayland root CLI issues and several Snap-related problems. Improved package dependencies, AppStream metadata, and desktop file handling. Fixed startup crashes when Python Requests is unavailable. Windows Fixed a security vulnerability that could allow arbitrary file deletion when cleaning with elevated privileges. Added %WindowsSystem% variable support. Improved clipboard clearing using native Windows APIs. Improved installer experience on unsupported Windows versions. Reduced installer size and improved application robustness. Fixed Unicode handling, filename anonymization, Git revision reporting, and splash screen stability. [full release notes] Download: BleachBit 6.0 | Portable | ~20.0 MB (Open Source) View: BleachBit Home page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • DriversCloud 12.1.6 by Razvan Serea With DriversCloud (formerly My-Config.com), you can explore your computer easily, safely and free. The application quickly scans your PC and identifies the hardware and software components. DriversCloud then establishes a list of the different drivers compatible with your OS and hardware. Download the drivers needed for the proper functioning of your computer. To detect your drivers, DriversCloud also displays a detailed summary of your hardware and software configuration, analyzes your BSOD, monitors in real-time your PC voltages and temperatures and lets you share your configuration online. Once the hardware components have been detected, you will be able to obtain with just a few clicks the latest drivers corresponding to the identified hardware. You can record your configuration on the site for free, and can get the corresponding URL to post the configuration to technical forums, e-mail and social networks. You can also download the detection result (the configuration) as a PDF file. To protect the user's privacy and data confidentiality, a 4-level confidentiality system was created that filters the XML marks and gives control to the user. The default level can be modified in the preferences. Using the maximum level will prevent the user from publishing his configuration and generating a corresponding PDF file. In non-connected mode, each XML configuration is stored on the server for one day (for practical reasons). However, you are given the opportunity to manually delete it. Created in 2004, and continually improved, My-Config.com has established itself on the web as a free service to PC users running Windows and Linux operating systems. The service is designed to work with the most common Internet browsers (Edge, Firefox, Chrome, Safari). Download: DriversCloud 64-bit | 20.0 MB (Freeware) Download: DriversCloud 32-bit | 18.9 MB Link: DriversCloud Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Month Later
      AndreaB earned a badge
      One Month Later
    • One Month Later
      agatameier earned a badge
      One Month Later
    • Week One Done
      agatameier earned a badge
      Week One Done
    • Week One Done
      ssd21345 earned a badge
      Week One Done
    • Contributor
      MarkHughes4096 went up a rank
      Contributor
  • Popular Contributors

    1. 1
      +primortal
      516
    2. 2
      +Edouard
      193
    3. 3
      PsYcHoKiLLa
      147
    4. 4
      ATLien_0
      96
    5. 5
      Steven P.
      77
  • Tell a friend

    Love Neowin? Tell a friend!