https网络编程——如何做web的访问控制机制(ACL)

Posted 行稳方能走远

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了https网络编程——如何做web的访问控制机制(ACL)相关的知识,希望对你有一定的参考价值。

参考:如何做web的访问控制机制(ACL)?
地址:https://qingmu.blog.csdn.net/article/details/108286660?spm=1001.2014.3001.5502

目录

ACL含义

对于一个服务器来说,我们不能让随随便便一个IP都可以访问我们的服务器,我们需要控制其访问的IP

例子

加入我们只能让C类段网络访问我们的服务器,那么我们就要对其进行访问控制

我们让C类段网络IP(192.168.1.1)与其掩码(255.255.255.0)做一个按位与,和访问的IP与这个掩码也做一个按位与的操作,其结果相同我们才能让其访问。

具体实现

int access_ornot(const char *destip) // 0 -> not 1 -> ok

	//192.168.1.1/255.255.255.0
	char ipinfo[16],maskinfo[16];
	char *p,*ip=ipinfo,*mask=maskinfo;
	char count=0;
	char *maskget=Getconfig("mask");
	const char *destipconst,*ipinfoconst,*maskinfoconst;
	if(maskget=="")
	
		printf("ok:%s\\n",maskget);
		return 1;
		
	p=maskget;

/* get ipinfo[] start */

	while(*p!='/')
	
		if(*p=='.')
			++count;
		*ip++=*p++;
	

	while(count<3)
	
		*ip++='.';
		*ip++='0';
		++count;
	
	*ip='\\0';

/* get ipinfo[] end */

/* get maskinfo[] start */

	++p;
	while(*p!='\\0')
	
		if(*p=='.')
			++count;
		*mask++=*p++;
	

	while(count<3)
	
		*mask++='.';
		*mask++='0';
		++count;
	
	*mask='\\0';

/* get maskinfo[] end */
	destipconst=destip;
	ipinfoconst=ipinfo;
	maskinfoconst=maskinfo;

	return ipadd_to_longlong(ipinfoconst)==(ipadd_to_longlong(maskinfoconst)&ipadd_to_longlong(destipconst));

以上是关于https网络编程——如何做web的访问控制机制(ACL)的主要内容,如果未能解决你的问题,请参考以下文章

Casbin + Gin + Gorm 学习探索

如何从控制器正确访问 HTTP 标头? (.NET 网络应用程序)

web安全学习-验证机制存在的问题

Squid缓存服务器(缓存机制代理模式ACL访问控制squid用户认证功能等)

WEB缓存控制机制与varnish简介

等保小知识什么是基于安全标记的访问控制机制?有什么特性?