portal认证服务器白名单

 
 
在路由器portal认证模块中,认证前用户是不能通过路由器上网的,但可以访问指定的域名,

portal认证模块中需要放行认证服务器的ip地址,域名对应的ip可能是多个,以下程序模拟
域名解析获取多个ip地址。

#include <stdio.h>
#include <netdb.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int add_white_ip_address(char * domain){
	int i = 0;
	struct hostent *he;
	struct in_addr *h_addr;
	char ip_addr[64] = {0};
	if ( !domain ) 
		return -1;

	he = gethostbyname(domain);

	if (he == NULL) {
		return 0;
	}
	while (he->h_addr_list[i] != 0)
  	{
		memset(ip_addr,0x0,sizeof(ip_addr));
  		strcpy(ip_addr,inet_ntoa(*(struct in_addr *)he->h_addr_list[i]));
		printf("%s[%d] = %s\n",domain,i,ip_addr);
		i++;	
  	}
	return 1;
}

int iptables_fw_init(void) {

	char * p = NULL;
	//char *p_white_domain_list = nvram_safe_get("white_domain_list");
	char *p_white_domain_list = "www.baidu.com;www.sina.com.cn;www.csdn.net;www.126.com;www.kuaiwifi.com";
	
	char white_domain_list_buf[512] = {0};
	struct in_addr *parse_addr;
	if (p_white_domain_list) {
		strcpy(white_domain_list_buf,p_white_domain_list);
		p = strtok(white_domain_list_buf,";");
		if ( p ) {
			printf("p=%s\n",p);
			
			add_white_ip_address(p); 
			while ((p = strtok(NULL,";")) != NULL) {
				printf("p = %s\n",p);
				add_white_ip_address(p); 
			}
		}
	}
}

int main()
{
	
	//add_white_ip_address("www.baidu.com"); 
	iptables_fw_init();
	return 0;
}











猜你喜欢

转载自blog.csdn.net/dxt1107/article/details/46503521