This tool obtains the public IP of this machine by accessing the http://city.ip138.com/ip2city.asp and parsing the content returned by it.
The source code is as follows.
UnitPublicipgetter;InterfacefunctionGETPUBLICIP:string;Implementationusessysutils, Windows, Classes, UrlMon;ConstCpublicipqueryurl:string='http://city.ip138.com/ip2city.asp';var_filename:string;functionPublicipfrompagetext (ConstSstring):string;ConstCipstarttoken='['; Cipendtoken=']';varI, J:integer;beginI:=Pos (Cipstarttoken, S); ifI >0 Then beginJ:=Pos (Cipendtoken, S); if(J >0) and(J > I) Then beginResult:= Copy (S, I +1, J-i-1); Exit; End; End; Result:="';End;functionGETPUBLICIP:string;varl:tstringlist;beginUrldownloadtofile (Nil, PChar (Cpublicipqueryurl), PChar (_filename),0,Nil); L:=tstringlist.create; L.loadfromfile (_filename); Result:=Publicipfrompagetext (L.text); Freeandnil (L); DeleteFile (PChar (_filename));End;initialization_filename:= Extractfilepath (Paramstr (0)) +'_ip_addr_tmp_.txt';End.
Get the public network IP