Updating the ip address with free domain

Started by carl_mathew, Nov 24, 2022, 04:39 AM

Previous topic - Next topic

carl_mathewTopic starter

There is often a situation when, due to the application of new settings on the home router or a banal restart, you have to climb to the site noip.com and change the IP address with handles. And if you are 200 or more kilometers away and you have no way to find out the address?
So I had (thank God I have) a remote IP address recognizer - my father, but he can also go on vacation, or be at work, and you need to update the address here and now.

Yes, you will say that routers have such a function for free domains and you will be right, but alas - either the router may be old, or this function does not work, or it only works in one domain zone. In short, there are a lot of nuances, but we also want everything to be like people.
An example of how this is not done in the stock firmware d-link dir320. Believe me, it is not a very rich and flexible way to configure (I love a zone other than ddns.net ). What is updated in the original firmware, what is not in the original through the ass, about the rest of the routers like Thomson, I'm generally silent, at least it works here :).

So, the service is actually not bad and provides an excellent api (pull at least through get or post - it works, which is good for use in a variety of situations and scenarios), which means it can be used both on a regular PC and on a server. In this case, it is used in a server with debian on board, and works as a backup option (just in case, since I will write about another, cooler script a little later if this material comes in).

Those who are interested can get acquainted with the api of the noip service here https://www.noip.com/integrate/request

Writing a script:

import re, urllib

if __name__ == "__main__":

web_page = urllib.urlopen("https://2ip.ru")

web_page = web_page.read()

ip = re.findall("(\d+\.\d+\.\d+\.\d+)", web_page)[0]

username = 'YOUR EMAIL'


host = 'YOUR HOST, BY THE TYPE OF THIS blog.bounceme.net '

update = urllib.urlopen("https://"+str(username)+":"+str(password)+

"@dynupdate.no-ip.com/nic/update?hostname="+str(host)+"&myip="+ ip)

res = update.read()

if re.match("(good)|(nochg)", res):

print 'ok'


print 'error\n' + res
What does the script do?

I think there is no point in explaining it here, if in general terms, then he goes to the probably well-known 2ip, parses your ip address from there, remembers it and then uses it in a variable, in the api of the noip service. When the script is successfully processed, the address in the service changes, and you receive the message "ok" in the terminal, otherwise an error message will be printed.

save it to the noip file.py and run python noip.py
We shove it into the crown and rejoice.


that was yesterday. Background - there is remote access to the internal network via VPN on the ASA. Everything is ok, but for some reason it is only available from 6 to 18.
And some particularly necessary people need access at night, for example. At the same time, only the main gateway is available, and people usually do not have white IP. In general, without hesitation, I made a temporary such scheme - an employee has a DDNS router, a script on the gateway that does dig and enters the current address in the login permissions.

Updated periodically. Here's a lady knocking on Viber last night- she won't let me in. I look at the address in the iptables tables - there is an address. I run a ping on DDNS-the name, the address is THE SAME. Ping really does not go, but who knows these home routers, maybe it blocks them.. in general, I did not attach much attention to this fact.
I ask the user to go to 2ip and dictate the address - the SAME dictates. i.e. everything seems to be on the ointment. But it doesn't work. I turn on the logging of everything that flies from this address on the gateway. We look at the log, thoughtfully ping the gateway from the user's computer, try to connect - but fuck.
We climb into the web muzzle of the home gateway - oppa, and the address is different.. In general, restart the router, restart the script on the gateway and everything worked, but the sediment remained - 2ip for some reason gave the old address.