#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
void readfile(){
FILE *host;
printf("\n");
char read[32767]="";
host=fopen("C:\\windows\\system32\\drivers\\etc\\hosts","rb");
fread(read,32000,1,host);
fclose(host);
printf("%s\n\n共计%d字节\n",read,strlen(read));
}
void bak(){
system("copy C:\\windows\\system32\\drivers\\etc\\hosts C:\\windows\\system32\\");
}
void res(){
system("copy C:\\windows\\system32\\hosts C:\\windows\\system32\\drivers\\etc\\");
}
void add(){
printf("请输入添加的屏蔽URL:");
FILE *host;
char temp[32767]="",d[200]="";
scanf("\n%[^\n]",d);
host=fopen("C:\\windows\\system32\\drivers\\etc\\hosts","rb");
fread(temp,32000,1,host);
fclose(host);
strcat(temp,"\n");
strcat(temp,"127.0.0.1 ");
strcat(temp,d);
host=fopen("C:\\windows\\system32\\drivers\\etc\\hosts","wb");
fputs(temp,host);
fflush(host);
fclose(host);
readfile();
printf("\n操作成功!\n");
}
void del(){
FILE *host;
int i=0;
char temp[32767]="";
host=fopen("C:\\windows\\system32\\drivers\\etc\\hosts","rb");
fread(temp,32000,1,host);
fclose(host);
for(i=strlen(temp)-1;i>0;i--){
if(temp[i]=='\n'){
temp[i]='\0';break;
}
}
host=fopen("C:\\windows\\system32\\drivers\\etc\\hosts","wb");
fputs(temp,host);
fflush(host);
fclose(host);
readfile();
printf("\n删除成功!\n");
}
void delask(){
char a[10];
readfile();
printf("\n\n是否删除最近一行的网址,请输入yes,否则视为放弃:");
scanf("%s",a);
if(strcmp(a,"yes")==0) {del();}
else {printf("您已放弃\n");}
}
int main(void){
while(1){
system("cls");
printf("####################网站屏蔽管理工具####################\n\n");
char a[20]="";
printf("操作提示:输入add添加屏蔽URL,del删除,list查看列表,close关闭,bak备份,res还原\n\n");
printf("请输入选项:");
scanf("%s",a);
printf("\n");
if(strcmp(a,"add")==0) add();
if(strcmp(a,"del")==0) delask();
if(strcmp(a,"close")==0) exit(-1);
if(strcmp(a,"list")==0) readfile();
if(strcmp(a,"bak")==0) bak();
if(strcmp(a,"res")==0) res();
printf("\n按回车键继续操作\n");
system("pause>nul");
}
}
731

被折叠的 条评论
为什么被折叠?



