#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<string.h>
#define MAX_LEN 255
typedef struct{ //表单数据名称和数据内容
char *name;
char *val;
}input;
char *ReadStdin(FILE *f, char stop, int *len); //表单中获取输入变量
void AddToSpace(char *str); //将+号变为空格
void Convert(char *url); //将特殊字符转化成十六进制
char *ReadData(char *line, char stop); //读取数据内容
int ip_is_legal(char *s);
int main(int argc, char *argv[])
{
printf("Content-type:text/html\n\n"); //声明content-type类型
printf("<body background = \"/plank.jpg\"");
printf("<br><strong><font size = +2 color=#FFFFFF>IP Information</font></strong>");
register int i;
register int m = 0;
int len;
len = atoi(getenv("CONTENT_LENGTH"));
input inputs[10];
for(i = 0; len &&(!feof(stdin)); i++){ //获取标准输入
m = i;
inputs[i].val = ReadStdin(stdin, '&', &len);
AddToSpace(inputs[i].val);
Convert(inputs[i].val);
inputs[i].name = ReadData(inputs[i].val,'=');
}
int flag;
char str1[20];
char str2[20];
char str3[20];
char str4[20];
strcpy(str1,inputs[0].val);
strcpy(str2,inputs[1].val);
strcpy(str3,inputs[2].val);
strcpy(str4,inputs[3].val);
if(0 != strlen(str1) && 0 != strlen(str2) && 0 != strlen(str3) &&0 != strlen(str4) && 0 == ip_is_legal(str1) && 0 == ip_is_legal(str2) && 0 == ip_is_legal(str3) && 0 == ip_is_legal(str4)){
flag = 1;}
else{
flag = 0;
printf("<br>");
printf("<br>");
printf("<br>");
printf("<br>");
printf("<br><strong><font color=#FFFFFF>Please input right IP !</font></strong>");
}
/*if(NULL != inputs[0].val && NULL != inputs[1].val && NULL != inputs[2].val && NULL != inputs[3].val)
{flag=1;}
else{
flag = 0;
printf("<p><center><strong>PLEASE INPUT IP ADDR!!!</center></p>");
}
*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(flag){
char buf1[] = "IP=";
char buf2[] = "Mask=";
char buf3[] = "Gateway=";
char buf4[] = "DNS=";
char buf5[] = "MAC=";
char buf_str1[256] = "";
char buf_str2[256] = "";
char buf_str3[256] = "";
char buf_str4[256] = "";
char buf_str5[256] = "08:90:90:90:90:90";
char buf_str6[256] = "";
strcat(buf_str1, buf1);
strcat(buf_str1, inputs[0].val);
strcat(buf_str2, buf2);
strcat(buf_str2, inputs[1].val);
strcat(buf_str3, buf3);
strcat(buf_str3, inputs[2].val);
strcat(buf_str4, buf4);
strcat(buf_str4, inputs[3].val);
strcat(buf_str6, buf5);
strcat(buf_str6, buf_str5);
FILE *fp_ip;
fp_ip = fopen("/etc/eth0-setting", "wb");
if(fp_ip == NULL){
printf("the network interfaces can not open\n");
exit(1);
}
fprintf(fp_ip,"%s\n",buf_str1);
fprintf(fp_ip,"%s\n",buf_str2);
fprintf(fp_ip,"%s\n",buf_str4);
fprintf(fp_ip,"%s\n",buf_str6);
fflush(fp_ip);
fclose(fp_ip);
printf("<p><center><font color=#FFFFFF>modify successfully!</font></center></p>");
printf("<p><center><strong><font color=#FFFFFF>if you want to make the modification come into force,please restart the system!</font></strong></center></p>");
}
printf("</body>");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
char *ReadStdin(FILE *f, char stop, int *len)
{
int wsize;
char *word;
wsize = 102400;
int x;
x =0;
word = (char *)malloc(sizeof(char) * (wsize + 1));
while(1){
word[x] = (char)fgetc(f);
if(x == wsize){
word[x + 1] = '\0';
wsize+=102400;
char *new_word = (char *)realloc(word, sizeof(char) * (wsize + 1));
word = new_word;
}
--(*len);
if((word[x] == stop) || (feof(f)) || (!(*len))){
if(word[x] != stop) x++;
word[x] = '\0';
return word;
}
++x;
}
}
char *ReadData(char *line, char stop)
{
int i = 0,j;
char *word = (char *)malloc(sizeof(char) * (strlen(line) + 1));
for(i = 0;((line[i])&&(line[i]!=stop)); i++)
word[i] = line[i];
word[i] = '\0';
if(line[i]) ++i;
j = 0;
while(line[j++] = line[i++]);
return word;
}
void AddToSpace(char *str)
{
register int i;
for(i = 0; str[i]; i++)
if(str[i] == '+')
str[i] = ' ';
}
char ConvertToHex(char *change)
{
register char hexdigit;
hexdigit = (change[0] >='A'? ((change[0] & 0xdf)-'A')+10:(change[0]-'0'));
hexdigit *=16;
hexdigit +=(change[1] >='A'? ((change[1] & 0xdf)-'A')+10:(change[1]-'0'));
return(hexdigit);
}
void Convert(char *data)
{
register int i,j;
for(i = 0, j = 0;data[j]; ++i,++j){
if((data[i] = data[j]) == '%'){
data[i] = ConvertToHex(&data[j+1]);
j+= 2;
}
}
data[i] = '\0';
}
int ip_is_legal(char *s)
{
int start = 0;//记录需分割字符串的起始位置
int end = 0; //记录当前字符串所遍历到字符的位置
int count = 0;//记录字符串中‘.’出现的次数
int i = 0;
int t = 0;
char *tmp = NULL;
char a[4][MAX_LEN];
memset(a, 0,sizeof(a));
if(s == NULL)
{return -1;}
for(tmp = s;*tmp;tmp++)
{
if((*tmp < '0' || *tmp >'9') && *tmp !='.')
{ return -1;}
if(*tmp == '.')
{
count++;
if(count > 3)
{return -1;}
memcpy(a[i], s+start, end-start);
a[i][end-start] = '\0';
i++;
start=end+1;
}
end++;
}
memcpy(a[i], s+start, end-start);
a[i][end-start] = '\0';
for(i=0; i<4; i++)
{
t = atoi(a[i]);
if(t < 0 || t > 255)
{return -1;}
}
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
boa.rar (34个子文件)
2013-07-20
right_date.htm 1KB
boa.conf 275B
plank.jpg 161KB
cgi-bin
version.c 3KB
plank.jpg 161KB
setip.c 6KB
setdate.c 4KB
restart.c 469B
passwd.c 4KB
about.c 1KB
Makefile 938B
recover.c 1KB
software.JPG 8KB
arm.jpg 58KB
gray.jpg 216KB
login.c 3KB
title.htm 746B
default.htm 2KB
llleft.htm 2KB
left.htm 2KB
temp.htm 1KB
index.htm 552B
right_about.htm 396B
right_passwd.htm 2KB
Thumbs.db 6KB
software.JPG 8KB
arm.jpg 58KB
gray.jpg 216KB
right_ip.htm 3KB
Data
write.c 1KB
login.txt~ 16B
write 7KB
login~ 16B
login 30B
共 34 条
- 1
资源评论
周楷雯
- 粉丝: 78
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功