/*这个程序是用来取得本地的IP,然后传到网上空间,有点向,动态域名解析*/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
void getip(void);/*方法取得IP*/
void writehtm(void);/*写入htm文件*/
void ftput(void);/*上传*/
void end(void);/*错误退出*/
int main()
{
getip();
writehtm();
ftput();
printf("/n/n/n成功!");
getch();/*界面停留*/
return 12;
}
void getip(void)
{
FILE *ip_txt,*ip_ip,*sz_ip;/*三个文件指针*/
char a,ip_chars[17];/*IP_chars为IP字符串数组*/
int n,num=0;/*记数*/
system("ipconfig>ip.txt");/*得到未加工的本地IP文件*/
ip_txt=fopen("ip.txt","r");/*去本地IP文件读取*/
while(!feof(ip_txt))
{
printf("%c",fgetc(ip_txt));//将本地文件输出
}
fclose(ip_txt);
if(fopen("sz.ip","r")==NULL)
{printf("请输入ip出现前/':/'号的次数:");
scanf("%d",&n);sz_ip=fopen("sz.ip","w"); //这个文件用来存出现次数
fprintf(sz_ip,"%d",n);//将IP前出现:号的次数记下,以便下次自动运行
fclose(sz_ip);
}
else
{
sz_ip=fopen("sz.ip","r");
fscanf(sz_ip,"%d",&n);//如果此文件存在就直截读取次数
fclose(sz_ip);
}
ip_txt=fopen("ip.txt","r");
while(!feof(ip_txt))
{
a=fgetc(ip_txt);
if(a==':')num++;
if(num==n){
fscanf(ip_txt,"%s",ip_chars);//这个字符串用来存IP信息
break;}
}
fclose(ip_txt);
ip_ip=fopen("ip.ip","w");//这个文件用来存IP地址
fprintf(ip_ip,"%s",ip_chars);//将IP存入ip.ip文件中
fclose(ip_ip);
}
void writehtm(void)//写htm文件函数
{
FILE *htm,*ex,*ip_ip;//htm为传上空间的htm文件,ex为本地所在的htm文件,ip_ip为存ip地址的文件
char ip_chars[17],a;//ip_Chars为iP数据
if(fopen("ex.htm","r")==NULL)//查看示例文件是否存在
{printf("示例文件不存在,按任意退出");end();}
ip_ip=fopen("ip.ip","r");
fscanf(ip_ip,"%s",ip_chars);//读取ip信息
fclose(ip_ip);
htm=fopen("ind.htm","w");//写要上传的文件
ex=fopen("ex.htm","r");
while(!feof(ex))
{
a=fgetc(ex);
if(a=='*')fprintf(htm,"%s",ip_chars);/*将'*'号用IP_char*替代,也就是**文件中要出现'*'*/
else fputc(a,htm);//其于的文件内容全部相同
}
fclose(htm);
fclose(ex);
}
void ftput(void)
{
FILE *ftp,*web;//web用于存ftp空间的地址,ftp是用来存ftp用户信息
char ftp_chars[100]="ftp -s:ftp.txt ",user[20],pass[20],http[50];
if(fopen("ftp.txt","r")==NULL&&fopen("web.txt","r")==NULL)//是否存在有用户信息,没有就建一个。
{
printf("/n请输入ftp域名:");//ftp空间的地址
scanf("%s",http);
printf("请输入用户名:");//FTP 空间用户
scanf("%s",user);
printf("请输入密码:");//密码
scanf("%s",pass);
strcat(ftp_chars,http);
strcat(user,"/n");
strcat(pass,"/n");
ftp=fopen("ftp.txt","w");
web=fopen("web.txt","w");
fprintf(web,"%s",http);//写入FTP地址
fclose(web);
fputs(user,ftp);//写入用户
fputs(pass,ftp);//写入密码
fputs("put ind.htm/n",ftp);//上传语句
fputs("close/n",ftp);//关闭连接
fputs("bye",ftp);//退也ftp
fclose(ftp);
}
else{web=fopen("web.txt","r");fscanf(web,"%s",http);strcat(ftp_chars,http);}/*如果存在ftp文件,就直接用*/
system(ftp_chars);//调用ftp并上传
}
void end(void)//有错误,退出程序
{
getch();
exit(0);//退也是
}
/*这个程序在运行前应该由自己写一个 名为ex.htm的文件 其格式大概为:
<iframe src=http://* 属性>
</iframe>
通过浏览器,访问ftp对应的web服务器下的 ind.htm就能访问到 ip 所指向的机器,先绝条件是 IP 对应的机子以经构架成web服务器,但其IP是动态。
*/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
void getip(void);/*方法取得IP*/
void writehtm(void);/*写入htm文件*/
void ftput(void);/*上传*/
void end(void);/*错误退出*/
int main()
{
getip();
writehtm();
ftput();
printf("/n/n/n成功!");
getch();/*界面停留*/
return 12;
}
void getip(void)
{
FILE *ip_txt,*ip_ip,*sz_ip;/*三个文件指针*/
char a,ip_chars[17];/*IP_chars为IP字符串数组*/
int n,num=0;/*记数*/
system("ipconfig>ip.txt");/*得到未加工的本地IP文件*/
ip_txt=fopen("ip.txt","r");/*去本地IP文件读取*/
while(!feof(ip_txt))
{
printf("%c",fgetc(ip_txt));//将本地文件输出
}
fclose(ip_txt);
if(fopen("sz.ip","r")==NULL)
{printf("请输入ip出现前/':/'号的次数:");
scanf("%d",&n);sz_ip=fopen("sz.ip","w"); //这个文件用来存出现次数
fprintf(sz_ip,"%d",n);//将IP前出现:号的次数记下,以便下次自动运行
fclose(sz_ip);
}
else
{
sz_ip=fopen("sz.ip","r");
fscanf(sz_ip,"%d",&n);//如果此文件存在就直截读取次数
fclose(sz_ip);
}
ip_txt=fopen("ip.txt","r");
while(!feof(ip_txt))
{
a=fgetc(ip_txt);
if(a==':')num++;
if(num==n){
fscanf(ip_txt,"%s",ip_chars);//这个字符串用来存IP信息
break;}
}
fclose(ip_txt);
ip_ip=fopen("ip.ip","w");//这个文件用来存IP地址
fprintf(ip_ip,"%s",ip_chars);//将IP存入ip.ip文件中
fclose(ip_ip);
}
void writehtm(void)//写htm文件函数
{
FILE *htm,*ex,*ip_ip;//htm为传上空间的htm文件,ex为本地所在的htm文件,ip_ip为存ip地址的文件
char ip_chars[17],a;//ip_Chars为iP数据
if(fopen("ex.htm","r")==NULL)//查看示例文件是否存在
{printf("示例文件不存在,按任意退出");end();}
ip_ip=fopen("ip.ip","r");
fscanf(ip_ip,"%s",ip_chars);//读取ip信息
fclose(ip_ip);
htm=fopen("ind.htm","w");//写要上传的文件
ex=fopen("ex.htm","r");
while(!feof(ex))
{
a=fgetc(ex);
if(a=='*')fprintf(htm,"%s",ip_chars);/*将'*'号用IP_char*替代,也就是**文件中要出现'*'*/
else fputc(a,htm);//其于的文件内容全部相同
}
fclose(htm);
fclose(ex);
}
void ftput(void)
{
FILE *ftp,*web;//web用于存ftp空间的地址,ftp是用来存ftp用户信息
char ftp_chars[100]="ftp -s:ftp.txt ",user[20],pass[20],http[50];
if(fopen("ftp.txt","r")==NULL&&fopen("web.txt","r")==NULL)//是否存在有用户信息,没有就建一个。
{
printf("/n请输入ftp域名:");//ftp空间的地址
scanf("%s",http);
printf("请输入用户名:");//FTP 空间用户
scanf("%s",user);
printf("请输入密码:");//密码
scanf("%s",pass);
strcat(ftp_chars,http);
strcat(user,"/n");
strcat(pass,"/n");
ftp=fopen("ftp.txt","w");
web=fopen("web.txt","w");
fprintf(web,"%s",http);//写入FTP地址
fclose(web);
fputs(user,ftp);//写入用户
fputs(pass,ftp);//写入密码
fputs("put ind.htm/n",ftp);//上传语句
fputs("close/n",ftp);//关闭连接
fputs("bye",ftp);//退也ftp
fclose(ftp);
}
else{web=fopen("web.txt","r");fscanf(web,"%s",http);strcat(ftp_chars,http);}/*如果存在ftp文件,就直接用*/
system(ftp_chars);//调用ftp并上传
}
void end(void)//有错误,退出程序
{
getch();
exit(0);//退也是
}
/*这个程序在运行前应该由自己写一个 名为ex.htm的文件 其格式大概为:
<iframe src=http://* 属性>
</iframe>
通过浏览器,访问ftp对应的web服务器下的 ind.htm就能访问到 ip 所指向的机器,先绝条件是 IP 对应的机子以经构架成web服务器,但其IP是动态。
*/