📄 writesysinfo.c
字号:
#include<sys/types.h>#include<stdio.h>#include <string.h>#include <unistd.h>#include <sys/stat.h>#include <fcntl.h>#include<stdlib.h>#define PATH "/config/"struct sysinfo { char ip[20]; char mask[20]; char gateway[20]; char dns[20]; char dns2[20]; char phonenum[20]; char sipserver[20]; } sysinfo1; write_sysinfo() { //state 8 var to read sip.webconf char AUDIO_CODEC_CURRENT[8]; char DEFAULT_SIP_SERVER_PORT[8]; char OUTBOUND_PROXY_SERVER_PORT[8]; char DEFAULT_RTP_RECEIVING_PORT[8]; char LOCAL_PHONE_NUMBER[20]; char LOCAL_USER_NAME[20]; char LOCAL_USER_PASSWORD[20]; char SIP_SERVER_NAME[20]; //read SIP info FILE *sipfpr; char filename_sip[100]; strcpy(filename_sip,PATH); strcat(filename_sip,"sip/sip.webconf"); //AUDIO_CODEC_CURRENT if ( (sipfpr=fopen(filename_sip,"r"))==NULL ) {printf("can not open sip.webconf to read!<br>\n"); } while(fscanf(sipfpr,"AUDIO_CODEC_CURRENT=%s\n",AUDIO_CODEC_CURRENT)!=EOF) { fscanf(sipfpr,"%*[^\n]%*c"); if (strlen(AUDIO_CODEC_CURRENT)!=0) break; } fclose(sipfpr); printf("AUDIO_CODEC_CURRENT=%s\n",AUDIO_CODEC_CURRENT); //DEFAULT_SIP_SERVER_PORT if ( (sipfpr=fopen(filename_sip,"r"))==NULL ) {printf("can not open sip.webconf to read!<br>\n"); } while(fscanf(sipfpr,"DEFAULT_SIP_SERVER_PORT=%s\n",DEFAULT_SIP_SERVER_PORT)!=EOF) { fscanf(sipfpr,"%*[^\n]%*c"); if (strlen(DEFAULT_SIP_SERVER_PORT)!=0) break; } fclose(sipfpr); printf("DEFAULT_SIP_SERVER_PORT=%s\n",DEFAULT_SIP_SERVER_PORT); //OUTBOUND_PROXY_SERVER_PORT if ( (sipfpr=fopen(filename_sip,"r"))==NULL ) {printf("can not open sip.webconf to read!<br>\n"); } while(fscanf(sipfpr,"OUTBOUND_PROXY_SERVER_PORT=%s\n",OUTBOUND_PROXY_SERVER_PORT)!=EOF) { fscanf(sipfpr,"%*[^\n]%*c"); if (strlen(OUTBOUND_PROXY_SERVER_PORT)!=0) break; } fclose(sipfpr); //DEFAULT_RTP_RECEIVING_PORT if ( (sipfpr=fopen(filename_sip,"r"))==NULL ) {printf("can not open sip.webconf to read!<br>\n"); } while(fscanf(sipfpr,"DEFAULT_RTP_RECEIVING_PORT=%s\n",DEFAULT_RTP_RECEIVING_PORT)!=EOF) { fscanf(sipfpr,"%*[^\n]%*c"); if (strlen(DEFAULT_RTP_RECEIVING_PORT)!=0) break; } fclose(sipfpr); //LOCAL_USER_NAME if ( (sipfpr=fopen(filename_sip,"r"))==NULL ) {printf("can not open sip.webconf to read!<br>\n"); } while(fscanf(sipfpr,"LOCAL_USER_NAME=%s\n",LOCAL_USER_NAME)!=EOF) { fscanf(sipfpr,"%*[^\n]%*c"); if (strlen(LOCAL_USER_NAME)!=0) break; } fclose(sipfpr); //LOCAL_USER_PASSWORD if ( (sipfpr=fopen(filename_sip,"r"))==NULL ) {printf("can not open sip.webconf to read!<br>\n"); } while(fscanf(sipfpr,"LOCAL_USER_PASSWORD=%s\n",LOCAL_USER_PASSWORD)!=EOF) { fscanf(sipfpr,"%*[^\n]%*c"); if (strlen(LOCAL_USER_PASSWORD)!=0) break; } fclose(sipfpr); //write configure file sip.webconf FILE *sipfpw; if ( !(sipfpw=fopen(filename_sip,"w+")) ) {printf("can not open sip.webconf to write!<br>\n"); } fprintf(sipfpw,"AUDIO_CODEC_CURRENT=%s\n",AUDIO_CODEC_CURRENT); fprintf(sipfpw,"DEFAULT_SIP_SERVER_PORT=%s\n",DEFAULT_SIP_SERVER_PORT); fprintf(sipfpw,"OUTBOUND_PROXY_SERVER_PORT=%s\n",OUTBOUND_PROXY_SERVER_PORT); fprintf(sipfpw,"DEFAULT_RTP_RECEIVING_PORT=%s\n",DEFAULT_RTP_RECEIVING_PORT); fprintf(sipfpw,"LOCAL_USER_NAME=%s\n",LOCAL_USER_NAME); fprintf(sipfpw,"LOCAL_USER_PASSWORD=%s\n",LOCAL_USER_PASSWORD); fprintf(sipfpw,"LOCAL_PHONE_NUMBER=%s\n",sysinfo1.phonenum); fprintf(sipfpw,"SIP_SERVER_NAME=%s\n",sysinfo1.sipserver); fclose(sipfpw); //read network info FILE *netfpr; char filename_net[100]; strcpy(filename_net,PATH); strcat(filename_net,"www/network.conf"); //NTPSERVER char ntpserver[100]; if ( (netfpr=fopen(filename_net,"r"))==NULL ) {printf("can not open network.conf to read!<br>\n"); } while(fscanf(netfpr,"export NTPSERVER=%s\n",ntpserver)!=EOF) { fscanf(netfpr,"%*[^\n]%*c"); if (strlen(ntpserver)!=0) break; } fclose(netfpr); //DHCPC char dhcpc; if ( (netfpr=fopen(filename_net,"r"))==NULL ) {printf("can not open network.conf to read!<br>\n"); } while(fscanf(netfpr,"export HCPC=%s\n",dhcpc)!=EOF) { fscanf(netfpr,"%*[^\n]%*c"); if (dhcpc!=' ') break; } fclose(netfpr); //DHCPD char dhcpd; if ( (netfpr=fopen(filename_net,"r"))==NULL ) {printf("can not open network.conf to read!<br>\n"); } while(fscanf(netfpr,"export DHCPD=%s\n",dhcpd)!=EOF) { fscanf(netfpr,"%*[^\n]%*c"); if (dhcpd!=' ') break; } fclose(netfpr); //write configure file network.conf FILE *netfpw; if ( !(netfpw=fopen(filename_net,"w+")) ) {printf("can not open network.conf to write!<br>\n"); } fprintf(netfpw,"export IPADDR=%s\n",sysinfo1.ip); fprintf(netfpw,"export NETMASK=%s\n",sysinfo1.mask); fprintf(netfpw,"export GATEWAY=%s\n",sysinfo1.gateway); fprintf(netfpw,"export DNS1=%s\n",sysinfo1.dns); fprintf(netfpw,"export DNS2=%s\n",sysinfo1.dns2); fprintf(netfpw,"export NTPSERVER=%s\n",ntpserver); fprintf(netfpw,"export DHCPC=%c\n",&dhcpc); fprintf(netfpw,"export DHCPD=%c\n",&dhcpd); fclose(netfpw);}main(){ strcpy(sysinfo1.ip,"192.168.3.100"); strcpy(sysinfo1.mask,"255.255.255.0"); strcpy(sysinfo1.gateway,"192.168.3.1"); strcpy(sysinfo1.dns,"192.168.3.1"); strcpy(sysinfo1.dns2,"61.235.70.98"); strcpy(sysinfo1.phonenum,"102"); strcpy(sysinfo1.sipserver,"192.168.3.111"); write_sysinfo(); printf("ip=%s\n",sysinfo1.ip); printf("mask=%s\n",sysinfo1.mask); printf("gateway=%s\n",sysinfo1.gateway); printf("dns=%s\n",sysinfo1.dns); printf("dns2=%s\n",sysinfo1.dns2); printf("phonenum=%s\n",sysinfo1.phonenum); printf("sipserver=%s\n",sysinfo1.sipserver);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -