-4

I'm building application that needs the hosting machine to change the IP every 30 minutes, can I do it programmatically without 3rd party applications?

Python is preferable, Java is welcome too.

Keppil
  • 45,603
  • 8
  • 97
  • 119
user1534151
  • 35
  • 1
  • 5
  • 3
    I think changing your IP requires that you contact your ISP. Also, this sounds like an attempt to get around a blacklist or a ban of some sort. – Mysticial Jul 18 '12 at 09:37
  • 6
    Every time you change the IP address you will lose all existing connections. If you are doing this for security reasons its a bad idea. If you are doing this for hacking purposes, its a really bad idea. – Peter Lawrey Jul 18 '12 at 09:38
  • 2
    which platform? which distro? – Kinjal Dixit Jul 18 '12 at 09:38
  • 1
    http://stackoverflow.com/questions/7580834/script-to-change-ip-address-on-windows answers this with win32 and WMI module – Vinayak Kolagi Jul 18 '12 at 09:38
  • @Peter: out of plain curiosity: why is this really bad for hacking? – Vlad Jul 18 '12 at 09:53
  • 30 minutes is still a long time in computing terms. I would expect hackers to rotate IP address as fast as they can (many times per second) – Peter Lawrey Jul 18 '12 at 09:56
  • guys, it's a study case, not every one asking about IP changing is a potential hacker. please, give some credit for a man, don't attack right away. – user1534151 Jul 18 '12 at 11:39

1 Answers1

4

If you want to change your external (Internet) IP address and if your machine is connected to the internet via dsl, and your ISP assigns you a dynamic IP, you can reboot your router (actually your dsl modem, but it's built into the router if you don't have an ages-old model) to get a new IP.

Rebooting the router programmatically can in theory be achieved with sending it a small SNMP packet telling it to reboot itself - given that the router follows protocol and correctly interprets the packet, and there's no firewall or other filter that blocks the SNMP message between you and the router.

In the common case, the SNMP OID to set would be 1.3.6.1.2.1.69.1.1.3 - you can do that with any language that has a SNMP library, there's pySNMP for python for example. Depending on your router model, it can be that you need a different OID or it doesn't have a way of being reset via SNMP at all.

Assuming your router ip is 192.168.0.1 and it accepts the default reset OID, something like this should work with pySNMP:

from pysnmp.entity.rfc3413.oneliner import cmdgen
from pysnmp.proto import rfc1902
cmdgen.CommandGenerator().setCmd(
    cmdgen.CommunityData('my-agent', 'public', 1),
    cmdgen.UdpTransportTarget(('192.168.0.1', 161)),
    ((1,3,6,1,2,1,69,1,1,3,0), rfc1902.Integer(1))
)
l4mpi
  • 5,103
  • 3
  • 34
  • 54
  • I'm pretty sure most ISP customers in the US do have dynamic IPs. – Wooble Jul 18 '12 at 12:14
  • is that so? then I guess my information on this is a bit outdated. It seems to have been the case that static IP was somewhat widespread in the US some years ago (judging from messageboard / irc / forum conversations and the like), I think it was at least way more common to have a static IP in the US than it was over here in Europe. I'll remove that comment from the answer. – l4mpi Jul 18 '12 at 12:35