python123监考_python--DenyHttp项目(2)--ACM监考客户端1.0版

#coding:gbk

importosimportsysfrom subprocess import *

importtimedefDenyfile():if not os.path.exists('D:\DenyHttp'):

os.mkdir('D:\DenyHttp')

os.mkdir(r'D:\DenyHttp\restore')

hostsName= 'C:\Windows\System32\drivers\etc\hosts'filename= r'D:\DenyHttp\hosts'

'''若存在原文件,删除'''

if os.path.exists(r'D:\DenyHttp\hosts') and os.path.exists(r'D:\DenyHttp\restore\hosts'):print(filename + '已存在!开始删除文件')

os.system("del /f /s /q D:\DenyHttp\*.*")

os.system("rd /s /q D:\DenyHttp")print('文件已经删除!')'''删除后创建新的目录'''

print('创建文件夹:')

os.system('mkdir d:\\DenyHttp\\restore')print('准备复制:')if not os.system(r'copy'+ hostsName +'D:\DenyHttp'):print('file remove from' + hostsName + 'to' +filename)if not os.system(r'copy'+ hostsName + r'D:\DenyHttp\restore'):print('file remove from' + hostsName + 'to D:\DenyHttp\restore')

L=[]

denyNetAddress=getHTTPList(L)'''添加htttp到文件'''

for s indenyNetAddress:

os.system('echo' + s +'>>' +filename)'''修改hosts文件'''

if not os.system(r'copy D:\DenyHttp\hosts C:\Windows\System32\drivers\etc'):print('file hosts has been already discovered!')defRecoverfile():if not os.system(r'copy D:\DenyHttp\restore\hosts C:\Windows\System32\drivers\etc'):print('file hosts has been already recovered!')defdetectnet():

L=[]

denyNetAddress=getNetList(L)

mark= 1

for s indenyNetAddress:

p= Popen(["ping.exe", s],

stdin=PIPE,stdout=PIPE,stderr=PIPE,

shell=True)

out=p.stdout.read()if '127.0.0.1' instr(out):

mark=0'''mark为假不能访问'''

if notmark:print('can\'t request http')else:print('can request http')returnmarkdef getHTTPList(denyNetAddress =[]):

denyNetAddress.append('127.0.0.1 sg.search.yahoo.com')

denyNetAddress.append('127.0.0.1 www.cnblogs.com')

denyNetAddress.append('127.0.0.1 www.baidu.com')

denyNetAddress.append('127.0.0.1 www.sogou.com')

denyNetAddress.append('127.0.0.1 blog.csdn.net')

denyNetAddress.append('127.0.0.1 www.soso.com')

denyNetAddress.append('127.0.0.1 cn.bing.com')'''1.0修复'''denyNetAddress.append('127.0.0.1 www.so.com')returndenyNetAddressdef getNetList(denyNetAddress =[]):

denyNetAddress.append('www.baidu.com')

denyNetAddress.append('www.sogou.com')

denyNetAddress.append('www.soso.com')

denyNetAddress.append('cn.bing.com')

denyNetAddress.append('www.so.com')

denyNetAddress.append('sg.search.yahoo.com')

denyNetAddress.append('www.cnblogs.com')

denyNetAddress.append('blog.csdn.net')returndenyNetAddressif __name__ == '__main__':#Denyfile()

Recoverfile()#print(detectnet())

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值