Skip to content

Instantly share code, notes, and snippets.

@flyfire
Created October 5, 2013 16:46
Show Gist options
  • Save flyfire/6843172 to your computer and use it in GitHub Desktop.
Save flyfire/6843172 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import urllib
import os
from shutil import copyfile
HOSTS_URL='https://smarthosts.googlecode.com/svn/trunk/hosts'
LOCAL_HOSTS='/etc/hosts'
def main():
#backup hosts
copyfile(LOCAL_HOSTS,'hosts.bak')
with open(LOCAL_HOSTS,'aw') as hosts:
hosts.write(os.linesep)
for line in urllib.urlopen(HOSTS_URL):
hosts.write(line.strip()+os.linesep)
print 'Success!'
if __name__ == '__main__':
if len(sys.argv) > 1:
HOSTS_URL = sys.argv[1]
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment