Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses
- IdHTTP, IdSSLOpenSSL, System.RegularExpressions;
- function GetIPAndCountry(var IP: string; var Country: string): Boolean;
- const
- UserAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko';
- var
- http: TIdHttp;
- ssl: TIdSSLIOHandlerSocketOpenSSL;
- buf: string;
- mch: TMatch;
- begin
- IP := '';
- Country := '';
- http := TIdHTTP.Create(nil);
- with http do
- try
- HandleRedirects := True;
- Request.UserAgent := UserAgent;
- ssl := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
- IOHandler := ssl;
- ConnectTimeout := 60000;
- ReadTimeout := 60000;
- buf := Get('https://2ip.ru/');
- if not buf.IsEmpty then
- begin
- mch := TRegEx.Match(buf, '>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})<');
- if mch.Success then
- IP := mch.Groups.Item[1].Value;
- mch := TRegEx.Match(buf, '\"\/geoip\/\"\/>([^\,<]+)');
- if mch.Success then
- Country := mch.Groups.Item[1].Value;
- end;
- finally
- FreeAndNil(http);
- FreeAndNil(ssl);
- end;
- Result := not (IP.IsEmpty and Country.IsEmpty);
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement