<!-- #include virtual="/include/data.inc" -->
<% on error resume next
Function ConvertIpToDbl(sIP)
    Dim sIps(3)
    Dim sIpTem  
    Dim i, j  
    Dim str  
    sIpTem = ""
    j = 0
    For i = 1 To Len(sIP)
       str = Mid(sIP, i, 1)
       If str <> "." Then
          sIpTem = sIpTem + str
       Else
          sIps(j) = sIpTem
          sIpTem = ""
          j = j + 1
       End If
       If i = Len(sIP) Then
          sIps(j) = sIpTem
       End If
    Next 
    For i = 0 To 3
        byIp = CByte(sIps(i))
        ConvertIpToDbl = ConvertIpToDbl + byIp * (2 ^ ((3 - i) * 8))
    Next
End Function



Public Function CStringIP(anNewIP)
    Dim lsResults
    Dim lnTemp
    Dim nTemp
    
    Dim lnIndex 
    
    For lnIndex = &H3 To &H0 Step -&H1
        
        lnTemp = Int(anNewIP / (&H100 ^ lnIndex))
        If lnTemp < 0 And lnIndex = &H3 Then
            nTemp = 256 - Abs(lnTemp)
            lsResults = lsResults & nTemp & "."
        Else
            lsResults = lsResults & lnTemp & "."
        End If
        anNewIP = anNewIP - (lnTemp * (&H100 ^ lnIndex))
    Next
    lsResults = Left(lsResults, Len(lsResults) - &H1)
    
    
        
    
    CStringIP = lsResults
End Function

function ConvertIPToVal(val)
   IPval=0
   if instr(val,".")>0 then
      Aarr=split(val,".")   '///拆分成数组
	  if Cint(Aarr(0))<128 then
	     IPval=Cint(Aarr(0))*256*256*256+Cint(Aarr(1))*256*256+Cint(Aarr(2))*256+Cint(Aarr(3))
	  else
	     IPval=-((256-Cint(Aarr(0)))*256*256*256-Cint(Aarr(1))*256*256-Cint(Aarr(2))*256-Cint(Aarr(3)))
	  end if
   end if
   ConvertIPToVal=IPval
end function

function transIP(val)   '///根据输入的ＩＰ范围得机器的macaddress集，从而得出查询条件
   sql="select * from tblpchistory H,tblpc pc where H.macid=pc.macid and ("
   if instr(val,",")>0 then
      sql=sql&" 1=2 "
      Aarr=split(val,",")   '///拆分成数组
	  cnt=ubound(Aarr)
      for i=0 to cnt
         if instr(Aarr(i),"-")>0 then    '///是否有"-"
	        Barr=split(Aarr(i),"-")
			sql=sql&" or (H.pcip in ("&IPSectToIP(Barr(0),Barr(1))&") )"
	     else
		    sql=sql&" or H.pcip='"&Aarr(i)&"' " 
		 end if
      next
	  sql=sql&")"
   else 
      if instr(val,"-")>0 then
	     B=split(val,"-")
		 sql=sql&" H.pcip in ("&IPSectToIP(B(0),B(1))&")"
	  else
         sql=sql&" H.pcip="&val&")"
	  end if
	  sql=sql&")"
   end if
   set rs_IP=server.createobject("adodb.recordset")
   'sql1="select * from tblpc"
   rs_IP.open sql,conn,3,1,1
   str_transIP="'',"
   do while not rs_IP.eof 
      if rs_IP.eof then
	     exit do
      end if
	  str_transIP=str_transIP&"'"&rs_IP("macaddress")&"',"
	  rs_IP.movenext
   loop
   str_transIP=str_transIP&"''"
   transIP=str_transIP

end function

function IPSectToIP(val1,val2)   '//找出符合用户输入的IP段的所有机器的IP．
   sql="select * from tblpchistory group by macid"
   set rs1=conn.execute(sql)
   IPval="'',"
   do while not rs1.eof 
      if rs1.eof then
	     exit do
	  end if
	  if CompareIP(val1,rs1("pcip"))="yes" and CompareIP(rs1("pcip"),val2)="yes" then
	     IPval=IPval&"'"&rs1("pcip")&"',"
	  end if
	  rs1.movenext
   loop
   IPval=IPval&"''"
   rs1.close
   set rs1=nothing
   IPSectToIP=IPval
end function

function CompareIP(val1,val2)
   IPval="yes"
   Arr1=split(val1,".")
   Arr2=split(val2,".")
   for i=0 to 3 
     if Cint(Arr2(i))<CInt(Arr1(i)) then
	   IPval="false"
	   exit for
	 end if
   next
   CompareIP=IPval  
end function
%>
