⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 networkcfg.c

📁 webserver
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************by grandchips #gcc -c NetworkCfg.c #gcc NetworkCfg.o -lpthread -o NetworkCfg.cgi****************************************************************************/#include<sys/types.h>#include<stdio.h>#include <string.h>#include <pthread.h>#include <unistd.h>#include <sys/stat.h>#include <fcntl.h>#define PATH "/config/www/"void *rq_ifconfig( ){         //printf("running rq_ifconfig\n");    if (fork()==0)     {              int fd;    char filename[100];    strcpy(filename,PATH);    strcat(filename,"ifconf.txt");    if((fd=open(filename,O_WRONLY|O_CREAT|O_TRUNC,0600))<0)       {         fprintf(stderr,"%s ","open file ifconf.txt error\n");          fd=creat("ifconf.txt",0600);        }   //printf("rq_ifconfig:%d\n",fd);   close(1);   dup(fd);                if (execl("/sbin/ifconfig","ifconfig","eth0",NULL)<0) perror("error in ifconfig");     close(fd);                  }   else        if (wait(NULL)==-1) printf("wait thread rq_ifconfig error!\n");  }void *rq_route( ){      //printf("running rq_route\n");    if (fork()==0)               {             int fd;    char filename[100];    strcpy(filename,PATH);    strcat(filename,"route.txt");    if((fd=open(filename,O_WRONLY|O_CREAT|O_TRUNC,0600))<0)       fprintf(stderr,"%s ","open file route.txt error");      //printf("rq_route:%d\n",fd);   close(1);   dup(fd);                if (execl("/sbin/route","route","-n",NULL)<0) perror("error in rq_route");     close(fd);                  } else        if (wait(NULL)==-1) printf("wait thread route.txt error!\n");  }void *rq_nslookup( ){   // printf("running rq_nslookup\n");     if (fork()==0)   {    char filename[100];    strcpy(filename,PATH);    strcat(filename,"nslookup.txt");               int fd;    if((fd=open(filename,O_WRONLY|O_CREAT|O_TRUNC,0600))<0)       printf("open file nslookup.txt error");    //printf("rq_nslookup:%d\n",fd);        close(1);   dup(fd);                if (execl("/usr/bin/nslookup","nslookup","server",NULL)<0) perror("error in nslookup");     close(fd);    }//child threadelse        if (wait(NULL)==-1) printf("wait thread nslookup error!\n");  }/****************************************************************************************************************************************************************************************/ main(){char mac[20];char ip[20];char mask[20];char gateway[20];char dns[20];char dns1[20];char dns2[20];char buf[50];strcpy(mac,"00:E0:EE:EC:D6:D8");strcpy(ip,"192.168.3.100");strcpy(mask,"255.255.255.0");strcpy(gateway,"192.168.3.1");strcpy(dns,"192.168.3.1#53");strcpy(dns1,"192.168.3.1");strcpy(dns2,"61.235.70.98");pthread_t if_status;pthread_t route_status;pthread_t nslookup_status;if(pthread_create(&nslookup_status,NULL,rq_nslookup,NULL)!=0)   exit(0);if(pthread_create(&if_status,NULL,rq_ifconfig,NULL)!=0)   exit(0);if(pthread_create(&route_status,NULL,rq_route,NULL)!=0)   exit(0); sleep(1);   //open require ifconfig file   FILE *fr;    char filename[100];    strcpy(filename,PATH);    strcat(filename,"ifconf.txt");  if ((fr= fopen(filename, "r")) == NULL) {   printf("Error in open require ifconfig file.\n");   exit(1);     };int words;for (words=1;words<20;words++){  if (words==5)  fscanf(fr,"%s",mac);  else if (words==7)  fscanf(fr,"%s",ip);  else if (words==9)  fscanf(fr,"%s",mask);  else fscanf(fr,"%s",buf);}   fclose(fr);//open require route file    strcpy(filename,PATH);    strcat(filename,"route.txt");  if ((fr= fopen(filename, "r")) == NULL) {   printf("Error in open route require file.\n");   exit(1);     };/*3210*/for (words=1;words<31;words++){  if (words==30)  fscanf(fr,"%s",gateway);  else fscanf(fr,"%s",buf);}/*dbm*//*for (words=1;words<23;words++){  if (words==22)  fscanf(fr,"%s",gateway);  else fscanf(fr,"%s",buf);}*/   fclose(fr);//open require nslookup file    strcpy(filename,PATH);    strcat(filename,"nslookup.txt");  if ((fr= fopen(filename, "r")) == NULL) {   printf("Error in open nslookup require file.\n");   exit(1);     };for (words=1;words<11;words++){  if (words==5)  fscanf(fr,"%s",dns);  else if (words==10)  fscanf(fr,"%s",dns2);  else fscanf(fr,"%s",buf);} fclose(fr); int i;for(i=0;i<20;i++){     if (dns[i]!='#')   dns1[i]=dns[i];   else    {dns1[i]='\0';break;   }}for(i=0;i<strlen(dns1);i++){   if (dns1[i]!='.' && (dns1[i]<'0' | dns1[i]>'9') )      {strcpy(dns1,"...");break;}}for(i=0;i<strlen(dns2);i++){   if (dns2[i]!='.' && (dns2[i]<'0' | dns2[i]>'9') )      {strcpy(dns2,"...");break;}}/****************************************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -