📄 liuip.pas
字号:
unit liuIP;
//通过IP转换成地址
//需要IP数据库IP.dll
interface
uses sysutils,classes,windows,liustr;
type
IPdat=record
startip,endip:int64;
adress:string[40];
end;
function IPToint(ip:string):int64;
function intToIP(i:int64):string;
function FindAdressFromIP(ip,datfile:string):string;
implementation
function IPToint(ip:string):int64;
var
ss:array[0..3]of string;
i:Integer;
begin
//222.81.51.114
if liustr.StrShumu(ip,'.')=4then
begin
try
liustr.fenjiestr(ip,'.',ss);
result:=strtoint(ss[0]);
for i:=1 to 3 do
begin
result:=(result shl 8)+strtoint(ss[i]);
end;
except
result:=0;
end;
end
else
begin
result:=0;
end;
end;
function intToIP(i:int64):string;
var
j1:int64;
begin
j1:=i-((i shr 8)shl 8);
result:='.'+inttostr(j1);
i:=i shr 8;
j1:=i-((i shr 8)shl 8);
result:='.'+inttostr(j1)+result;
i:=i shr 8;
j1:=i-((i shr 8)shl 8);
result:='.'+inttostr(j1)+result;
i:=i shr 8;
j1:=i-((i shr 8)shl 8);
result:=inttostr(j1)+result;
end;
function FindAdressFromIP(ip,datfile:string):string;
var
fl:file of ipdat;
rd:ipdat;
b,e,i:integer;
fd:boolean;
l:int64;
begin
result:='未知IP';
if fileexists(datfile) then
begin
assignfile(fl,datfile);
reset(fl);
l:=iptoint(ip);
b:=0;
e:=filesize(fl);
fd:=false;
while not fd do
begin
i:=(e-b)div 2+b;
seek(fl,i);
read(fl,rd);
if (l>=rd.startip)and(l<=rd.endip) then
begin
fd:=True;
result:=rd.adress;
break;
end
else if l<rd.startip then
begin
e:=i;
end
else
begin
b:=i;
end;
if l<=b then break;
end;
closefile(fl);
end
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -