海外邮件中继,海外退信中继,美国高速VPS,不限流量VPN,邮局维护和管理,邮件网关,EMOS邮件中继,POSTFIX邮件中继,Winwebmail邮件中继,Winmail邮件中继,DBMail邮件中继,JDMail邮件中继,Exchange邮件中继,MDaemon邮件中继 淘宝店:http://shantan.taobao.com 云邮科技官网:www.yunrelay.com
【字体设置:大 中 小】
把以下代码直接保存为一个文件,比如:inc.asp,然后在需要的页面利用包含关系包含进来就可以直接使用了,而标准格式的纯真IP数据库你到网上搜索一下,到处都可以下载到,建议到大型网站去下载,免得小网站的程序放了病毒什么的。
要获取客户端的IP地址的时候,直接用<%=getIP()%>就可以获得了,如果要获得IP对用的地址,可以用<%=getaddress(getIP())%>,使用起来相当的方便。
建议大家直接到纯真网站去下载IP数据库,网址是:http://www.cz88.net/
======================================================
以下为程序代码,其中增加了两个参数,一个是IPCOUNT,即IP数据的记录数量
一个是UPTIME,即数据库更新的数据,你可以根据情况修改,然后再其它页面调用。
======================================================
<%
IPCount="374895"
uptime="2009-12-15"
Private Function getIP()
Dim sjmp5_IPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR")="" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
sjmp5_IPAddr=Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
sjmp5_IPAddr=Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),1,InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),";") > 0 Then
sjmp5_IPAddr=Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),1,InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),";")-1)
Else
sjmp5_IPAddr=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP=Trim(Mid(sjmp5_IPAddr,1,30))
End Function
sjmp5_ipaddes=getIP()
Function GetAddress(IP)
Dim sjmper,sjmp5_Type
Set sjmper=New Tsjmp5_ipr
sjmp5_Type=sjmper.sjmp5_ipr(IP)
GetAddress=sjmper.sjmp5_Countr&sjmper.sjmp5_Locstr
Set sjmper = Nothing
End Function
Class Tsjmp5_ipr
Dim sjmp5_Countr,sjmp5_Locstr,Buf,OffSet
Private StartIP,EndIP,sjmp5_Countrsjmp5_Flag
Public FirstStartIP,LastStartIP,RecordCount,sjmp5_iprFile
Private Stream,EndIPOff
Private Sub Class_Initialize
sjmp5_Countr=""
sjmp5_Locstr=""
StartIP=0
EndIP=0
FirstStartIP=0
LastStartIP=0
EndIPOff=0
sjmp5_iprFile=Server.MapPath("QQWry.dat")
End Sub
Function IP2Int(IP)
Dim IPArray,i
IPArray=Split(IP,".",-1)
FOr i=0 to 3
If Not IsNumeric(IPArray(i)) Then IPArray(i)=0
If CInt(IPArray(i))<0 Then IPArray(i)=Abs(CInt(IPArray(i)))
If CInt(IPArray(i))>255 Then IPArray(i)=255
Next
IP2Int=(CInt(IPArray(0))*256*256*256)+(CInt(IPArray(1))*256*256)+(CInt(IPArray(2))*256)+CInt(IPArray(3))'-1
End Function
Function Int2IP(IntValue)
p4=IntValue-Fix(IntValue/256)*256
IntValue=(IntValue-p4)/256
p3=IntValue-Fix(IntValue/256)*256
IntValue=(IntValue-p3)/256
p2=IntValue-Fix(IntValue/256)*256
IntValue=(IntValue-p2)/256
p1=IntValue
Int2IP=Cstr(p1)&"."&Cstr(p2)&"."&Cstr(p3)&"."&Cstr(p4)
End Function
Private Function GetStartIP(RecNo)
OffSet=FirstStartIP+RecNo * 7
Stream.Position=OffSet
Buf=Stream.Read(7)
EndIPOff=AscB(MidB(Buf,5,1))+(AscB(MidB(Buf,6,1))*256)+(AscB(MidB(Buf,7,1))*256*256)
StartIP=AscB(MidB(Buf,1,1))+(AscB(MidB(Buf,2,1))*256)+(AscB(MidB(Buf,3,1))*256*256)+(AscB(MidB(Buf,4,1))*256*256*256)
GetStartIP=StartIP
End Function
Private Function GetEndIP()
Stream.Position=EndIPOff
Buf=Stream.Read(5)
EndIP=AscB(MidB(Buf,1,1))+(AscB(MidB(Buf,2,1))*256)+(AscB(MidB(Buf,3,1))*256*256)+(AscB(MidB(Buf,4,1))*256*256*256)
sjmp5_Countrsjmp5_Flag=AscB(MidB(Buf,5,1))
GetEndIP=EndIP
End Function
Private Sub Getsjmp5_Countr(IP)
If (sjmp5_Countrsjmp5_Flag=1 or sjmp5_Countrsjmp5_Flag=2) Then
sjmp5_Countr=Getsjmp5_FlagStr(EndIPOff+4)
If sjmp5_Countrsjmp5_Flag=1 Then
sjmp5_Locstr=Getsjmp5_FlagStr(Stream.Position)
If IP>= IP2Int("255.255.255.0") And IP<=IP2Int("255.255.255.255") Then
sjmp5_Locstr=Getsjmp5_FlagStr(EndIPOff+21)
sjmp5_Countr=Getsjmp5_FlagStr(EndIPOff+12)
End If
Else
sjmp5_Locstr=Getsjmp5_FlagStr(EndIPOff+8)
End If
Else
sjmp5_Countr=Getsjmp5_FlagStr(EndIPOff+4)
sjmp5_Locstr=Getsjmp5_FlagStr(Stream.Position)
End If
sjmp5_Countr=Trim(sjmp5_Countr)
sjmp5_Locstr=Trim(sjmp5_Locstr)
If InStr(sjmp5_Countr,"CZ88.NET") Then sjmp5_Countr=""
If InStr(sjmp5_Locstr,"CZ88.NET") Then sjmp5_Locstr=""
End Sub
Private Function Getsjmp5_FlagStr(OffSet)
Dim sjmp5_Flag
sjmp5_Flag=0
Do While (True)
Stream.Position=OffSet
sjmp5_Flag=AscB(Stream.Read(1))
If(sjmp5_Flag=1 or sjmp5_Flag=2 ) Then
Buf=Stream.Read(3)
If (sjmp5_Flag=2 ) Then
sjmp5_Countrsjmp5_Flag=2
EndIPOff=OffSet-4
End If
OffSet=AscB(MidB(Buf,1,1))+(AscB(MidB(Buf,2,1))*256)+(AscB(MidB(Buf,3,1))*256*256)
Else
Exit Do
End If
Loop
If (OffSet<12 ) Then
Getsjmp5_FlagStr=""
Else
Stream.Position=OffSet
Getsjmp5_FlagStr=GetStr()
End If
End Function
Private Function GetStr()
Dim sjmp5_c
GetStr=""
Do While (True)
sjmp5_c=AscB(Stream.Read(1))
If (sjmp5_c=0) Then Exit Do
If sjmp5_c>127 Then
If Stream.EOS Then Exit Do
GetStr=GetStr&Chr(AscW(ChrB(AscB(Stream.Read(1)))&ChrB(sjmp5_C)))
Else
GetStr=GetStr&Chr(sjmp5_c)
End If
Loop
End Function
Public Function sjmp5_ipr(DotIP)
Dim IP,nRet
Dim RangB,RangE,RecNo
IP=IP2Int(DotIP)
Set Stream=CreateObject("ADodb.Stream")
Stream.Mode=3
Stream.Type=1
Stream.Open
Stream.LoadFromFile sjmp5_iprFile
Stream.Position=0
Buf=Stream.Read(8)
FirstStartIP=AscB(MidB(Buf,1,1))+(AscB(MidB(Buf,2,1))*256)+(AscB(MidB(Buf,3,1))*256*256)+(AscB(MidB(Buf,4,1))*256*256*256)
LastStartIP=AscB(MidB(Buf,5,1))+(AscB(MidB(Buf,6,1))*256)+(AscB(MidB(Buf,7,1))*256*256)+(AscB(MidB(Buf,8,1))*256*256*256)
RecordCount=Int((LastStartIP-FirstStartIP)/7)
If (RecordCount<=1) Then
sjmp5_Countr="Unknow"
sjmp5_ipr=2
Exit Function
End If
RangB=0
RangE=RecordCount
Do While (RangB<(RangE-1))
RecNo=Int((RangB+RangE)/2)
Call GetStartIP (RecNo)
If (IP=StartIP) Then
RangB=RecNo
Exit Do
End If
If (IP>StartIP) Then
RangB=RecNo
Else
RangE=RecNo
End If
Loop
Call GetStartIP(RangB)
Call GetEndIP()
If (StartIP<=IP) And ( EndIP>=IP) Then
nRet=0
Else
nRet=3
End If
Call Getsjmp5_Countr(IP)
sjmp5_ipr=nRet
End Function
Private Sub Class_Terminate()
On ErrOr Resume Next
Stream.Close
If Err Then Err.Clear
Set Stream=Nothing
End Sub
End Class
sjmp5_ipaddess=getIP()
sjmp5_ipaddess_zw=getaddress(sjmp5_ipaddess)
%>
发表评论 - 不要忘了输入验证码哦!