#!/usr/bin/env python  
# coding=gb2312  
  
'此程序通过修改hosts加速Gmail网页的打开,仅用于ipv4'  
  
import os  
import socket  
  
pingaddress = 'www.google.cn'  
ls = os.linesep  
  
if os.name == 'nt':  
    print "您使用的是 Windows NT 内核操作系统n"  
    hosts = open(r'C:WindowsSystem32driversetchosts', 'a')  
elif os.name == 'posix':  
    print "您使用的是 Unix / 
linux 内核操作系统n"  
    hosts = open('/etc/hosts', 'a')  
elif os.name == 'mac':  
    print "您使用的是 Mac OS X 操作系统n"  
    hosts = open('/Private/etc/hosts', 'a')  
[python] view plaincopyprint?
else:  
    print "您的操作系统不受支持或者无法识别,程序退出"  
    exit(0)  
  
try:  
    pingip = socket.gethostbyname(pingaddress)  
except socket.gaierror:  
    print "解析DNS失败,请检查您的
网络连接!n"  
    pingip = '203.208.46.144'  
  
ip = pingip+' mail.google.com'  
  
print "已将'www.google.cn'的对应IP地址记录为:", 'n', ip, 'n'  
  
hosts.write(ls)  
hosts.write('# Gmail加速程序')  
hosts.write(ls)  
hosts.writelines('%s%s' % (ip, ls))  
hosts.write(ls)  
hosts.close()  
print '已更改hosts,重启浏览器生效!'