├── LICENSE ├── README.md ├── crowall.exe ├── crowall.py └── downloadicon.png /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2014-2016 racaljk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # crosswall 2 | :heart: 翻墙小工具,适合学术粉使用 3 | 4 | 5 | 点击下载---->>>>>>> 6 | 7 | 更多细节,可以参考下面的文章链接 http://blog.csdn.net/marksinoberg/article/details/52943194 8 | --- 9 | 10 | 先说说这个小工具的原理吧,就是替换hosts文件。然后其依赖于GitHub上一个维护小组( https://github.com/racaljk/hosts )的hosts更新文件。 11 | 12 | 然后这个工具在每次运行的时候,都会自动的下载最新的hosts文件,并在备份当前的hosts文件为hosts_bak后自动的完成替换工作。 13 | 14 | 由于是系统盘内的文件操作,所以需要有复制和替换的权限,请右键以管理员的权限运行。祝您使用愉快:-) 15 | 16 | ![示意](http://img.blog.csdn.net/20161026151543539) 17 | 18 | 19 | -------------------------------------------------------------------------------- /crowall.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HostsTools/Windows-python/761b1e8d4b0fda8eee2cb8495ab3ea17d5901d77/crowall.exe -------------------------------------------------------------------------------- /crowall.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import sys 3 | 4 | reload(sys) 5 | sys.setdefaultencoding('utf8') 6 | # __author__ = '郭 璞' 7 | # __date__ = '2016/10/24' 8 | # __Desc__ = 翻墙助手, 默认会先备份一下当前的hosts文件,防止出现意外,另外可以跨平台使用 9 | 10 | import platform 11 | import os 12 | import urllib2 13 | 14 | def downloadHosts(url): 15 | file = open('./hosts.txt', 'wb') 16 | data = urllib2.urlopen(url).readlines() 17 | file.writelines(data) 18 | file.close() 19 | 20 | 21 | 22 | def crosswall(systemtype='Window'): 23 | try: 24 | if systemtype == 'Windows': 25 | os.system('copy %SystemRoot%\System32\drivers\etc\hosts %SystemRoot%\System32\drivers\etc\hosts_bak') 26 | os.system('copy hosts.txt %SystemRoot%\System32\drivers\etc\hosts') 27 | os.system('ipconfig /flushdns') 28 | os.system('pause') 29 | print 'It\'s done on Windows! And Try your browser!' 30 | elif systemtype == "Linux": 31 | os.system('cp /etc/hosts.txt /etc/hosts_bak') 32 | os.system('mv ./hosts /etc/hosts') 33 | os.system('pause') 34 | os.system('sudo /etc/init.d/networking restart ') 35 | print 'It\'s done on Linux! And Try your browser!' 36 | elif systemtype == "Darwin": 37 | os.system('sudo cp /etc/hosts /etc/host_bak') 38 | os.system('sudo mv ./hosts.txt /etc/hosts') 39 | os.system('sudo ifconfig en0 down && sudo ifconfig en0 up') 40 | print 'It\'s done on Mac! And Try your browser!' 41 | except Exception as e: 42 | print e 43 | 44 | 45 | 46 | if __name__ == '__main__': 47 | 48 | url = 'https://raw.githubusercontent.com/googlehosts/hosts/master/hosts-files/hosts' 49 | downloadHosts(url=url) 50 | print 'Hosts update success!' 51 | crosswall(platform.system()) 52 | print 'Hosts replaced success! Try to cross the wall!' 53 | -------------------------------------------------------------------------------- /downloadicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HostsTools/Windows-python/761b1e8d4b0fda8eee2cb8495ab3ea17d5901d77/downloadicon.png --------------------------------------------------------------------------------