当前位置导航:炫浪网>>网络学院>>网页制作>>ASP教程

VBS 纯真IP数据库转MDB/MSSQL/MySQL

Function Mappath(n)
    Mappath=Fso.getabsolutepathname(n)
End Function

Function IpToNum(Ip)
    IpNs=split(ip,".")
    IpN=IpNs(0)*S4+IpNs(1)*S3+IpNs(2)*S2+IpNs(3)*S1
    if err<>0 then IpN=0
    err.clear
    IpToNum=IpN
End Function

S1=256
S2=256*S1
S3=256*S2
S4=256*S3
on error resume next
Set Fso=CreateObject("Scripting.FileSystemObject")
Set Conn=CreateObject("ADODB.Connection")
Conn.open "provider=microsoft.jet.oledb.4.0;data source="&Mappath("dat.mdb")

Set Rs=CreateObject("ADODB.Recordset")
Rs.open "S elect * from d",Conn,2,3

Set Fto=Fso.OpenTextFile(Mappath("dat.txt"))
Do while not Fto.atendofstream
    Rs.addnew
    Res=Split(Replace(Replace(Fto.Readline,"    ",""),"  "," ")," ")
    Rs("s")=IpToNum(Res(0))
    Rs("e")=IpToNum(Res(1))
    Rs("c")=Res(2)
    Rs("h")=Res(3)
    Wscript.Echo "From "&Res(0)&" To "&Res(1)&" Updated."
    Rs.update
Loop
Rs.close


注意S elect中间有空格,复制时候请去掉中间空格。复制代码,保存另存为.vbs 即可。

将纯真数据库转MSSQL数据库也很简单,只需改

 程序代码
Conn.open “driver={SQL Server}; server=(local);database= ;uid= ;pwd= ”


将纯真数据库转MYSQL数据库,只需改

 程序代码
Conn.open “Driver={mysql};database=[yourdatabase];uid=[username];pwd=[yourpassword];option=16386;”

相关内容
赞助商链接