Created
August 10, 2013 18:01
-
-
Save k14i/6201463 to your computer and use it in GitHub Desktop.
This may be useful when you don't use dynamic DNS sevices.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import urllib2 | |
import re | |
import os | |
import socket | |
#hostname = socket.gethostname() | |
hostname = "" | |
urlprovider = 'http://www.ugtop.com/' | |
targetnode = '' | |
targetsshdport = '22' | |
targetdir = "~/var/globalipaddrinfo/%(hostname)s" % locals() | |
targetfile = "%(targetdir)s/ipaddr" % locals() | |
privatekey = '~/.ssh/id_rsa' | |
regex = re.compile('^([0-9]{1,3})(\.([0-9]{1,3})){3}') | |
file = urllib2.urlopen(urlprovider) | |
for line in file: | |
matchobject = regex.match(line) | |
if matchobject == None: | |
continue | |
else: | |
ipaddressstring = matchobject.group() | |
cmd = "ssh -i %(privatekey)s -p %(targetsshdport)s %(targetnode)s \"mkdir -p %(targetdir)s; echo %(ipaddressstring)s > %(targetfile)s\"" % locals() | |
os.system(cmd) | |
break | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment