![]() |
AW: Whois from IP-Adresse?
Fehler gefunden: Buffer muss AnsiChar sein!
|
AW: Whois from IP-Adresse?
So sollte es funktionieren, Uses anpassen (ich nutze D2009 ^_^)
Delphi-Quellcode:
uses WinInet;
function GetUrlContent(const Url: string): UTF8String; var NetHandle: HINTERNET; UrlHandle: HINTERNET; Buffer: array[0..1023] of byte; BytesRead: dWord; StrBuffer: UTF8String; begin Result := ''; NetHandle := InternetOpen('Delphi 2009', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); if Assigned(NetHandle) then try UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0); if Assigned(UrlHandle) then try repeat InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead); SetString(StrBuffer, PAnsiChar(@Buffer[0]), BytesRead); Result := Result + StrBuffer; until BytesRead = 0; finally InternetCloseHandle(UrlHandle); end else raise Exception.CreateFmt('Cannot open URL %s', [Url]); finally InternetCloseHandle(NetHandle); end else raise Exception.Create('Unable to initialize Wininet'); end; |
AW: Whois from IP-Adresse?
Zitat:
|
AW: Whois from IP-Adresse?
Zitat:
|
AW: Whois from IP-Adresse?
Wahrscheinlich Ja.:thumb:
Also bei Dir mit dem Winapi Namespace bei mir ohne. |
AW: Whois from IP-Adresse?
Funktioniert ausgezeichnet. Danke!
|
AW: Whois from IP-Adresse?
Gern geschehen, in der Repeat Schleife könntest Du das ganze auch in eine StringList ausgeben lassen um auf #1-#14 einzeln zugreifen zu können, aber mach wie Du magst, jetzt weißt Du ja wie es funktioniert :wink:
|
AW: Whois from IP-Adresse?
So habe ich es nun bei mir, um noch mehr Informationen zu erhalten.
Delphi-Quellcode:
type
ApiResults = record Status: UTF8String; Country: UTF8String; CountryCode: UTF8String; RegionState: UTF8String; RegionName: UTF8String; City: UTF8String; Zip: UTF8String; Latitude: UTF8String; Longitude: UTF8String; CityTimeZone: UTF8String; ISP: UTF8String; Organization: UTF8String; NumberName: UTF8String; DNS: UTF8String; MobileConnection: UTF8String; ProxyConnection: UTF8String; QueryIP: UTF8String; ErrorMessage: UTF8String; end; function GetUrlContentData(const Url: string): UTF8String; var NetHandle: HINTERNET; UrlHandle: HINTERNET; Buffer: array[0..1023] of byte; BytesRead: dWord; StrBuffer: UTF8String; begin Result := ''; NetHandle := InternetOpen('Delphi 2009', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); if Assigned(NetHandle) then try UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0); if Assigned(UrlHandle) then try repeat InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead); SetString(StrBuffer, PAnsiChar(@Buffer[0]), BytesRead); Result := Result + StrBuffer; until BytesRead = 0; finally InternetCloseHandle(UrlHandle); end else raise Exception.CreateFmt('Cannot open URL %s', [Url]); finally InternetCloseHandle(NetHandle); end else raise Exception.Create('Unable to initialize Wininet'); end; function GetUrlContent(const Url: string): ApiResults; begin Result.Status := GetUrlContentData(Url+'?fields=status'); if Pos('fail', LowerCase(Result.Status)) > 0 then begin Result.ErrorMessage := GetUrlContentData(Url+'?fields=message'); Result.QueryIP := GetUrlContentData(Url+'?fields=query'); end else begin Result.Country := GetUrlContentData(Url+'?fields=country'); Result.CountryCode := GetUrlContentData(Url+'?fields=countryCode'); Result.RegionState := GetUrlContentData(Url+'?fields=region'); Result.RegionName := GetUrlContentData(Url+'?fields=regionName'); Result.City := GetUrlContentData(Url+'?fields=city'); Result.Zip := GetUrlContentData(Url+'?fields=zip'); Result.Latitude := GetUrlContentData(Url+'?fields=lat'); Result.Longitude := GetUrlContentData(Url+'?fields=lon'); Result.CityTimeZone := GetUrlContentData(Url+'?fields=timezone'); Result.ISP := GetUrlContentData(Url+'?fields=isp'); Result.Organization := GetUrlContentData(Url+'?fields=org'); Result.NumberName := GetUrlContentData(Url+'?fields=as'); Result.DNS := GetUrlContentData(Url+'?fields=reverse'); Result.MobileConnection := GetUrlContentData(Url+'?fields=mobile'); Result.ProxyConnection := GetUrlContentData(Url+'?fields=proxy'); Result.QueryIP := GetUrlContentData(Url+'?fields=query'); end; end; procedure TForm1.Button1Click(Sender: TObject); var ThisLines: ApiResults; begin ThisLines := GetUrlContent('http://ip-api.com/line/' + 'ip-api.com'); Memo1.Lines.Add('Status: '+ThisLines.Status); if Pos('fail', LowerCase(ThisLines.Status)) > 0 then begin Memo1.Lines.Add('ErrorMessage: '+ThisLines.ErrorMessage); Memo1.Lines.Add('QueryIP: '+ThisLines.QueryIP); end else begin Memo1.Lines.Add('Country: '+ThisLines.Country); Memo1.Lines.Add('CountryCode: '+ThisLines.CountryCode); Memo1.Lines.Add('RegionState: '+ThisLines.RegionState); Memo1.Lines.Add('RegionName: '+ThisLines.RegionName); Memo1.Lines.Add('City: '+ThisLines.City); Memo1.Lines.Add('Zip: '+ThisLines.Zip); Memo1.Lines.Add('Latitude: '+ThisLines.Latitude); Memo1.Lines.Add('Longitude: '+ThisLines.Longitude); Memo1.Lines.Add('CityTimeZone: '+ThisLines.CityTimeZone); Memo1.Lines.Add('ISP: '+ThisLines.ISP); Memo1.Lines.Add('Organization: '+ThisLines.Organization); Memo1.Lines.Add('NumberName: '+ThisLines.NumberName); Memo1.Lines.Add('DNS: '+ThisLines.DNS); Memo1.Lines.Add('MobileConnection: '+ThisLines.MobileConnection); Memo1.Lines.Add('ProxyConnection: '+ThisLines.ProxyConnection); Memo1.Lines.Add('QueryIP: '+ThisLines.QueryIP); end; end; |
AW: Whois from IP-Adresse?
Wenn Du die Funktion GetUrlContent() hiermit ersetzt ist/zählt es als nur 1 Internet-Abruf.
Delphi-Quellcode:
Viel Spaß damit.
function GetUrlContent(const Url: string): ApiResults;
var tmp: UTF8String; sl: TStrings; begin tmp := GetUrlContentData(Url+'?fields=status,country,countryCode,region,regionName,city,zip,lat,lon,timezone,isp,org,as,reverse,mobile,proxy,query,message'); try sl := TStringList.Create; sl.Text := tmp; Result.Status := sl[0]; if Pos('fail', LowerCase(Result.Status)) > 0 then begin Result.ErrorMessage := sl[1]; Result.QueryIP := sl[2]; end else begin Result.Country := sl[1]; Result.CountryCode := sl[2]; Result.RegionState := sl[3]; Result.RegionName := sl[4]; Result.City := sl[5]; Result.Zip := sl[6]; Result.Latitude := sl[7]; Result.Longitude := sl[8]; Result.CityTimeZone := sl[9]; Result.ISP := sl[10]; Result.Organization := sl[11]; Result.NumberName := sl[12]; Result.DNS := sl[13]; Result.MobileConnection := sl[14]; Result.ProxyConnection := sl[15]; Result.QueryIP := sl[16]; end; finally sl.Free; tmp := ''; end; end; |
AW: Whois from IP-Adresse?
Zitat:
Hier findet man informationen über eine IP-Adresse wie Land, Region, stadt, Postleitzahl, Latitude , Longitude usw... ![]() |
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:06 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz