前提条件,空间必须支持aspjpeg组件
1 数据库,使用dvbbs的ip数据库,改名为ip.mdb,放在当前文件夹的data文件夹
2 conn.asp 连接数据库代码,简单的写成了
<%
set conn=server.createobject("adodb.connection")
DBPath = Server.MapPath("data\IP.MDB")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPath
%>
3 ip.asp 主程序
<!--#include file="conn.asp"-->
<%
Response.ContentType = "image/gif"
mm=Request.ServerVariables("HTTP_USER_AGENT")
m=Split(mm,";")
if Ubound(m)>=3 then
c1=m(1)
c2=m(2)
else
c1="未知"
c2="未知"
end if
'获取客户端ip信息,并查找相关位置
CIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If CIP = "" or IsNull(CIP) Then CIP = Request.ServerVariables("REMOTE_ADDR")
IP = Split(CIP,".")
if Ubound(IP)=3 then
For i=0 To Ubound(IP)
IP(i)=left(IP(i),3)
if isnumeric(IP(i)) then
IP(i)=cint(IP(i))
else
IP(i)=0
end if
next
myipnumeber=IP(0)*256*256*256+IP(1)*256*256+IP(2)*256+IP(3)-1
End If
sql="select country,city from DV_Address where IP1<="&myipnumeber&" and IP2>="&myipnumeber
set rs=conn.execute(sql)
if not rs.eof Then
country = rs(0)
city = rs(1)
Else
country = "未知IP"
city = ""
End If
Dim LocalFile,TargetFile
LocalFile = Server.MapPath("ip.jpg")
Dim Jpeg
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.Open (LocalFile) '打开图片
Dim aa
aa=Jpeg.Binary '将原始数据赋给aa
'=========加文字水印=================
Jpeg.Canvas.Font.Color = &H000000 '水印文字颜色
Jpeg.Canvas.Font.Family = "宋体" '字体
Jpeg.Canvas.Font.Bold = False '是否加粗
Jpeg.Canvas.Font.Size = 14 '字体大小
Jpeg.Canvas.Font.ShadowColor = &Hffffff '阴影色彩
Jpeg.Canvas.Font.ShadowYOffset = 1
Jpeg.Canvas.Font.ShadowXOffset = 1
Jpeg.Canvas.Brush.Solid = False
Jpeg.Canvas.PrintText 30,30,"-------------------------------------" '水印位置及文字
Jpeg.Canvas.PrintText 30,50," 你的IP: "& CIP
Jpeg.Canvas.PrintText 30,70," 你的位置: "&country & "--"&city
Jpeg.Canvas.PrintText 30,90," 操作系统:"& c2
Jpeg.Canvas.PrintText 30,110," 浏 览 器: "& c1
Jpeg.Canvas.PrintText 30,130,"-------------------------------------"
Jpeg.Canvas.PrintText 30,145,"听涛小筑.........."
bb=Jpeg.Binary
'============调整文字透明度================
Set MyJpeg = Server.CreateObject("Persits.Jpeg")
MyJpeg.OpenBinary aa
Set Logo = Server.CreateObject("Persits.Jpeg")
Logo.OpenBinary bb
MyJpeg.DrawImage 0,0, Logo, 1 '0.3是透明度
cc=MyJpeg.Binary '将最终结果赋值给cc,这时也可以生成目标图片了
Response.BinaryWrite cc '将二进输出给浏览器
%>
4 图片,制作一张用于显示的图片,起名为ip.jpg,放在当前目录了,如果更改了存放目录,请在程序中自行修改路径
引用,<img src="http://www.XXX.XXX/ipimg/ip.asp" />即可,如果在论坛里用ubb语法签名,引用为{img}
http://www.xxxx.xxx/ipimg/ip.asp{/img},其中ipimg是你存在的文件夹
程序就不多做解释了