function TfmPrintServiceTykj.GetLocalIP: string;
var
mstr: string;
ss: TStringList;
i, iIpAddress, iSubNet: integer;
begin
ss := TStringList.Create;
try
try
WinExec(‘cmd /c ipconfig >c:\temp.txt’, SW_HIDE);
sleep(1000);
ss.LoadFromFile(‘c:\temp.txt’);
for i := 0 to ss.Count - 1 do
begin
mstr := mstr + ss[i];
end;
mstr := copy(mstr, pos(‘本地连接’, mstr), length(mstr));
if Pos(‘IPv4 地址’, mstr) > 0 then
begin
iIpAddress := pos(‘IPv4 地址’, mstr);
iSubNet := pos(‘子网掩码’, mstr);
mstr := Copy(mstr, iIpAddress, iSubNet - iIpAddress);
mstr := Copy(mstr, pos(‘:’, mstr) + 1, length(mstr));
mstr := Trim(mstr);
end else if Pos(‘IP Address’, mstr) > 0 then
begin
iIpAddress := pos(‘IP Address’, mstr);
iSubNet := pos(‘Subnet Mask’, mstr);
mstr := Copy(mstr, iIpAddress, iSubNet - iIpAddress);
mstr := Copy(mstr, pos(‘:’, mstr) + 1, length(mstr));
mstr := Trim(mstr);
end else
begin
mstr := ‘’;
end
finally
ss.Destroy;
// DeleteFile(‘c:\temp.txt’);
end
except
end;
result :=mstr;
end;