CloudFlare Dynamic DNS

Here’s a simple Python script that can be called with your CloudFlare credentials to update the IP address with the address of the connecting machine.

Be sure to input your own information in the Email field, API key, base domain, record type, and record name. Any comments, I’d love to hear them.

I suggest running this script as a cron job set to run every 30 minutes or so, depending on your usage. Also, it doesn’t hurt to run it with the nice command!
[Download | GitHub Repository]

#Change the following

cloudflareEmail="[email protected]" #CF Login Email Address
cloudflareAPIkey="yourlonglowercaseandnumberapikey" #API Key as shown on https://www.cloudflare.com/my-account

#the following credentials will update the A record for example.thebasedomainname.com with the IP address of the connecting machine
baseDomain='thebasedomainname.com' #Domain Name as shown on https://www.cloudflare.com/my-websites.html
recordType='A' #See "Type" Column on https://www.cloudflare.com/dns-settings?z=example.com
recordName='example' #See "Name" Column on https://www.cloudflare.com/dns-settings?z=example.com

import os,re
import urllib
import sys

#Find the CloudFlare ID of your (sub)domain based on the recordName and recordType
data={'a': 'rec_load_all','tkn': cloudflareAPIkey,'email': cloudflareEmail,'z': baseDomain}
data = urllib.urlencode(data)
f = urllib.urlopen("https://www.cloudflare.com/api_json.html", data)
recloadall=f.read()
#print recloadall
recloadall=recloadall[0:recloadall.find('"display_name":"'+str(recordName)+'","type":"'+str(recordType)+'"')]
recordID=recloadall[recloadall.rfind("rec_id")+9:recloadall.find('","',recloadall.rfind("rec_id")+9)]
#print recordID
if recordID.find(':"error"')>-1:
recordID=recordID[recordID.find('"msg":"')+6:recordID.find(",",recordID.find('"msg":"')+3)]
print "CF Record:",recordID

#Get your current device IP Address
f = urllib.urlopen("http://ip-api.com/xml")
ipe=f.read()
ip=ipe[ipe.find("< ![CDATA[")+16:ipe.rfind("]]>",ipe.find("< ![CDATA["))].strip() print "IP Address:",ip #Update with Cloudflare data={'a': 'rec_edit','tkn': cloudflareAPIkey,'id': recordID,'email': cloudflareEmail,'z': baseDomain,'type': recordType,'name': recordName,'content': ip,'service_mode': '0','ttl': '1'} data = urllib.urlencode(data) f = urllib.urlopen("https://www.cloudflare.com/api_json.html", data) response=f.read() #print response print "Update:",response[response.find('result":')+9:response.find(',',response.find('result":')+3)-1]

Cheers!

Google Crawl Trends

Hello World!
I’m working on creating a tool that allows for better management and viewing of the data provided in Google’s Webmaster Tools. Specifically, I’m designing it to prevent the loss of all this data after 90 Days / 1 Year (depending on the statistic).
I was wondering if anyone has any features they would want in such a tool (e.g. crawl trend or traffic trend prediction) or if you wouldn’t mind sharing your google webmaster tools info with me via the add user feature- please contact me.
Cheers!

Python Code to Reset Linksys / OBI / Motorola Modem

The following code can be run as a cron job on your computer or, ideally, your linux based network attached storage

Upon loss of internet connection, it resets most motorola cable modems (common with Charter Communications) and also many Linksys / Cisco Routers. Optionally, it can be configured to reset an OBI VoIP device. If you have any questions or additions, feel free to comment or email me!

[download file, GitHub Repisotory ]

import os,re
import urllib
import urllib2
import sys
import time, base64

#This try/except block will first reset the Motorola Modem if the internet works.
#Be sure your modem page can be accessed from http://192.168.100.1 and reset from http://192.168.100.1/reset.htm 
#Only certain modems have this feature, so delete or comment out this block if it doesn't work for your model
try:
	urllib.urlopen("http://74.125.224.72")  #This attempts to access Google by their direct IP address
	print "Fetch Success, Internet Works! :)"
except:
	print "Fetch Error, Internet is currently down :("
	print "\tResetting Modem"
	urllib.urlopen("http://192.168.100.1/reset.htm")
	print "\tModem Reset, waiting 120 seconds to check again..."
	time.sleep(120)

#This block resets OBI Devices. Only uncomment if you are using a OBI VoIP device. Be sure you can access your device at http://192.168.10.1/ (if not, change it to the proper address)
#Enter your correct password in OBIPASSWORD
''' 
OBIPASSWORD="Your password here"
try:
	urllib.urlopen("http://74.125.224.72")
	print "Fetch Success, Internet Works!"
except:
	print "\tInternet Still Down, Resetting OBI"
	handler = urllib2.HTTPDigestAuthHandler()
	handler.add_password("[email protected]","http://192.168.10.1/rebootgetconfig.htm","admin", str(OBIPASSWORD))
	opener = urllib2.build_opener(handler)
	urllib2.install_opener(opener)
	opened=urllib2.urlopen("http://192.168.10.1/rebootgetconfig.htm")
	print "\tOBI Reset, waiting 120 seconds to restart router..."
	time.sleep(60)
'''

#This block resets many Cisco/Linksys routers via the Reboot button on the homepage
#be sure your router can be accessed at http://192.168.1.1 and input your credentials below. 
USERNAME="admin"
PASSWORD="admin" 
try:
	urllib.urlopen("http://74.125.224.72")
	print "Fetch Success, Internet Works!"
except:
	print "\tInternet Still Down, Resetting Router"
	req = urllib2.Request("http://192.168.1.1/apply.cgi")
	base64string = base64.encodestring('%s:%s' % (str(USERNAME), str(PASSWORD)))[:-1]
	authheader =  "Basic %s" % base64string
	req.add_header("Authorization", authheader)
	req.add_data("submit_button=index&change_action=gozila_cgi&submit_type=reboot&timer_interval=30")
	handle = urllib2.urlopen(req)

Cheers!