在FB中将上站IP改为自定说明.
功能: 其实就是将IP换成域名了什么的.因为我想将一个网段用同一个说明,
用系统的hosts就很麻烦,好像也没什么做过这个东东就用了.
如:在数据文件中将211.66.114.*这个段说明成"暨大真茹19",那么用
这个段的IP上BBS的地址将显示成"暨大真茹19"
用法: 1) 数据文件(默认是"etc/host")格式
如:
# begin IP end IP note
#=========================================
202.116.9.61 暨南园BBS
211.66.114.93 真茹BBS站
211.66.114.1 211.66.114.255 暨大真茹19
~~~网段开始IP ~~~网段结束IP ~~~说明
注: *如果只有开始IP就类似于系统hosts啦,只有那个IP才说明
*返回第一个找到的说明,如211.66.114.93同时符合"真茹BBS站"
与"暨大真茹19"两个说明的要求,但是由于会先找到在前边的
记录,所以返回的说明是"真茹BBS站"
2) getnote.c 源程序附后
程序中:
#define MAXCOUNT 100 // 最多的数据条数
#define HOSTFILE "etc/host" // 数据文件
3) 加入BBS中
在你想用这个功能的时候,就#include "getnote.c"
然后就用setip2add(IP)返回说明就行了
setip2add()的声明:
char* setip2add (char* ip);
如果想在进站的时候就开始改了,可以在bbsd.c中#include "getnote.c"
在main()中:
getremotename(&xsin, fromhost);
if (bad_host(fromhost)) exit(1); /* ban 掉 bad host / bad user */
后加上:
strncpy(fromhost, setip2add(fromhost), 16); // 将fromhost改成说明
源程序:
//source: getnote.c
/*
* JNU fishchen, gethostfromip Preview, fishchen@cnhelp.net , 2001.11.5
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MAXCOUNT 100 // 最大记录数
#define HOSTFILE "etc/host" // 数据文件
char host[MAXCOUNT][3][16];
int readdata (void) {
FILE* fp;
char t[256], * t1, * t2, * t3;
int counts;
counts=0;
if ( (fp = fopen(HOSTFILE, "r")) == NULL ) return 0;
while ( fgets(t, 255, fp) && counts<=MAXCOUNT) {
t1 = strtok(t, " \t");
t2 = strtok(NULL, " \t\n");
t3 = strtok(NULL, " \t\n");
if ( t1[0]=='#' || t1==NULL || t2==NULL ) continue;
if (t3==NULL) {
strncpy(host[counts][0], t1, 16);
strncpy(host[counts][1], NULL, 0);
strncpy(host[counts][2], t2, 16);
} else {
strncpy(host[counts][0], t1, 16);
strncpy(host[counts][1], t2, 16);
strncpy(host[counts][2], t3, 16);
}
counts++;
}
fclose(fp);
return counts;
}
/*
* cmpip(),
* error then 0
* ip1==ip2 then return 1
* ip1<ip2 then return 2
* ip1>ip2 then return 3
*/
int cmpip(char* ip1, char* ip2) {
char temp[2][4], * p_temp1, * p_temp2;
int i, j, i_ip1, i_ip2;
if (ip1==NULL && ip2==NULL) return 0;
p_temp1=ip1;
p_temp2=ip2;
for (i=0; i<4; i++) {
j=0;
while (p_temp1[0]!='\0' && p_temp1[0]!='.') {
if (j>3) return 0;
temp[0][j]=p_temp1[0];
p_temp1++;
j++;
}
temp[0][j]='\0';
p_temp1++;
j=0;
while (p_temp2[0]!='\0' && p_temp2[0]!='.') {
if (j>3) return 0;
temp[1][j]=p_temp2[0];
p_temp2++;
j++;
}
temp[1][j]='\0';
p_temp2++;
if ( (i_ip1=atoi(temp[0]))>255 || (i_ip2=atoi(temp[1]))>255 ) return 0;
if ( i_ip1<i_ip2 ) return 2;
if ( i_ip1>i_ip2 ) return 3;
}
return 1;
}
char* getadd(char* ip, int counts) {
int i;
for (i=0; i<counts; i++) {
if ( host[i][1]==NULL ) {
if ( cmpip(ip, host[i][0])==1 ) return host[i][2];
} else {
if ( ((cmpip(ip, host[i][0])==3) && (cmpip(ip, host[i][1])==2))
|| cmpip(ip, host[i][0])==1
|| cmpip(ip, host[i][1])==1 )
return host[i][2];
}
}
return ip;
}
char* setip2add (char* ip) {
int counts;
counts=readdata();
return getadd(ip, counts);
}
// source end.
--
修改:fishchen FROM 211.66.114.31
FROM 211.66.114.31