uses winsock;function IpInScope(Ip, IpStart, IpEnd: string): Boolean; var nIp, nIpStart, nIpEnd: Integer; begin nIpStart:=ntohl(inet_addr(PChar(IpStart))); nIpEnd:=ntohl(inet_addr(PChar(IpEnd))); nIp:=ntohl(inet_addr(PChar(Ip))); Result:=(Ip>=IpStart)and(Ip<=IpEnd); end; .... if IpInScope('127.0.0.1','127.0.0.1','127.33.33.0') then begin ShowMessage('ok'); end;
帮楼上的修改一下笔误:function IpInScope(Ip, IpStart, IpEnd: string): Boolean; var nIp, nIpStart, nIpEnd: DWORD; begin nIpStart := ntohl(inet_addr(PChar(IpStart))); nIpEnd := ntohl(inet_addr(PChar(IpEnd))); nIp := ntohl(inet_addr(PChar(Ip))); Result := (nIp >= nIpStart) and (nIp <= nIpEnd); end;
uses winsock;function IpInScope(Ip, IpStart, IpEnd: string): Boolean;
var
nIp, nIpStart, nIpEnd: Integer;
begin
nIpStart:=ntohl(inet_addr(PChar(IpStart)));
nIpEnd:=ntohl(inet_addr(PChar(IpEnd)));
nIp:=ntohl(inet_addr(PChar(Ip)));
Result:=(Ip>=IpStart)and(Ip<=IpEnd);
end;
....
if IpInScope('127.0.0.1','127.0.0.1','127.33.33.0') then
begin
ShowMessage('ok');
end;
var
nIp, nIpStart, nIpEnd: DWORD;
begin
nIpStart := ntohl(inet_addr(PChar(IpStart)));
nIpEnd := ntohl(inet_addr(PChar(IpEnd)));
nIp := ntohl(inet_addr(PChar(Ip)));
Result := (nIp >= nIpStart) and (nIp <= nIpEnd);
end;