(原创程序)用C语言编写PC屏蔽网址管理器,任何浏览器都打不开!

#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");
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值