对客户端的ip限制函数

'******************************
'Function CheckIp(cInput_Ip,cBound_Ip)
'Created by qqdao, qqdao@263.net 2001/11/28
'说明:首先需要根据;号循环,然后判断是否含有"-",如果有则进行拆分处理,最后判断是否在范围内
'参数: cInput_Ip,代检查的ip
' cBound_Ip,给定的范围格式为,单个ip,和范围ip,范围ip最后使用”-“分割,如果是“*”则必须放到最后一位
' 每个范围后添加":ALLOW"表示允许登陆,添加":REFUSE"表示拒绝登陆。多个范围用”;“隔开
' 例如192.168.1*.*:ALLOW;192.168.1.1:ALLOW;192.168.1.1-10:REFUSE"
'返回值: true/false
'更新:2001/12/05 支持ALLOW,REFUSE支持’*‘,不想对?支持,因为和*差不多
'******************************
function CheckIp(cInput_Ip,cBound_Ip)
dim cSingle_Ip,cTemp_IP,cStart_IP,cEnd_Ip
CheckIp = false
cSingle_Ip=split(cBound_Ip,";")

for I=0 to ubound(cSingle_Ip)
if Instr(cSingle_Ip(I),"REFUSE") <> 0 then '就是拒绝了
cTemp_IP = left(cSingle_Ip(I),instr(cSingle_Ip(I),":")-1)

if Instr(cTemp_IP,"*") <> 0 then '是宽范围
cStart_IP = left(cTemp_IP,instr(cTemp_IP,"*")-1)
if left(cInput_Ip,len(cStart_IP))=cStart_IP then
CheckIp = false
exit function
end if
end if

if Instr(cTemp_IP,"-") = 0 then
cStart_IP = cTemp_IP
cEnd_Ip = cTemp_IP
else
cStart_IP = left(cTemp_IP,instr(cTemp_IP,"-")-1)
cEnd_Ip = left(cStart_IP,InStrRev(cStart_IP,".")-1)+"."+mid(cTemp_IP,instr(cTemp_IP,"-")+1)
end if

if Ip2Str(cInput_Ip)>=Ip2Str(cStart_IP) and Ip2Str(cInput_Ip)<=Ip2Str(cEnd_Ip) then
CheckIp = false
exit function
end if

elseif Instr(cSingle_Ip(I),"ALLOW") <> 0 then '允许

cTemp_IP = left(cSingle_Ip(I),instr(cSingle_Ip(I),":")-1)

if Instr(cTemp_IP,"*") <> 0 then '是宽范围
cStart_IP = left(cTemp_IP,instr(cTemp_IP,"*")-1)
if left(cInput_Ip,len(cStart_IP))=cStart_IP then
CheckIp = true
end if
end if

if Instr(cTemp_IP,"-") = 0 then
cStart_IP = cTemp_IP
cEnd_Ip = cTemp_IP
else
cStart_IP = left(cTemp_IP,instr(cTemp_IP,"-")-1)
cEnd_Ip = left(cStart_IP,InStrRev(cStart_IP,".")-1)+"."+mid(cTemp_IP,instr(cTemp_IP,"-")+1)
end if

if Ip2Str(cInput_Ip)>=Ip2Str(cStart_IP) and Ip2Str(cInput_Ip)<=Ip2Str(cEnd_Ip) then
CheckIp =true
else
CheckIp =false
end if
end if
next

end function


'******************************
'Function Ip2Str(cIp)
'Created by qqdao, qqdao@263.net 2001/11/28
'参考动网ip算法
'参数:cIp ip地址
'返回值: 转换后数值
'******************************

function Ip2Str(cIp)
Dim str1,str2,str3,str4
Dim cIp_Temp
if cIp="127.0.0.1" then cIp="192.168.0.1"
str1=left(cIp,instr(cIp,".")-1)
cIp_Temp=mid(cIp,instr(cIp,".")+1)
str2=left(cIp_Temp,instr(cIp_Temp,".")-1)
cIp_Temp=mid(cIp_Temp,instr(cIp_Temp,".")+1)
str3=left(cIp_Temp,instr(cIp_Temp,".")-1)
str4=mid(cIp_Temp,instr(cIp_Temp,".")+1)

if isNumeric(str1)=0 or isNumeric(str2)=0 or isNumeric(str3)=0 or isNumeric(str4)=0 then

else
Ip2Str=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)-1
end if

end function
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Qt是一种流行的跨平台应用程序开发框架,其中包含了一些用于网络通信的类。其中之一就是Qt的QTcpServer类,它提供了一种简单的方式来创建一个TCP服务器。 使用QTcpServer类,我们可以方便地实现多个客户端连接到服务器的功能。首先,我们需要创建一个QTcpServer对象,并调用其listen()函数来监听指定的IP地址和端口。当有客户端连接到服务器时,QTcpServer会自动触发一个新的连接信号newConnection(),我们可以使用一个槽函数来处理这个信号。 在槽函数中,我们可以调用QTcpServer的nextPendingConnection()函数来获取新的连接,然后将其保存到一个QList或QVector中,以便于对它们进行管理。每个连接都代表一个与客户端的通信通道,我们可以通过调用QTcpSocket的相应函数来读取和写入数据。 为了处理多个客户端连接,我们可以使用Qt的事件循环机制。在每次循环中,我们可以遍历保存连接的列表,检查是否有新的数据可读取。我们可以使用QIODevice的readyRead()信号来实现这一功能,当有数据可读取时,我们可以调用QTcpSocket的相应函数来读取数据。 另外,我们还可以设置QTcpServer的maxPendingConnections属性来限制同时连接到服务器的客户端数量。当达到最大连接数时,后续的连接请求会被服务器忽略。 总的来说,使用QTcpServer实现多个客户端连接的功能相对简单,我们只需要注意管理连接对象和使用事件循环机制来处理数据即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值