码迷,mamicode.com
首页 > 其他好文 > 详细

portal认证服务器白名单

时间:2015-06-15 16:36:25      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:域名解析   c语言   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;
}



技术分享








portal认证服务器白名单

标签:域名解析   c语言   portal   

原文地址:http://blog.csdn.net/dxt1107/article/details/46503521

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!