Autor Beitrag
Talbot
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44

Win 2000, Win98, WinXP Prof, Linux(Suse, Gentoo, Debian, RedHat)
D6 Enterprise
BeitragVerfasst: Mi 20.08.03 11:09 
Hi. Folgendes.
Mit dem Tool iDIPWatch kann man ja ganz einfach die Lokale IP-Adresse auslesen. Nun häng ich aber en nem Router und möchte meine Globale IP Adresse ermitteln. Was muss ich dafür tun?

Gruß, Talbot
Ak-Alex
Gast
Erhaltene Danke: 1



BeitragVerfasst: Mi 20.08.03 12:18 
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
uses ClipBrd; 

{$R *.dfm} 

procedure TForm1.Button1Click(Sender: TObject); 
var 
  InetIP: string
  WebAddress, SearchString: string
  Buff, P, FT: PChar; 
  BuffLen: Word; 
  StartPos, StringLength, TempInt: Integer; 
begin 
  WebAddress   := 'http://www.whatismyip.com/'
  SearchString := 'Your ip is '
  Memo1.Clear; 
  try 
    NMHTTP1.Get(WebAddress); 
  except 
    on E: Exception do 
    begin 
      MessageDlg('Could not get IP Address! ' + 
        'Please ensure you are connected to ' + 
        'the Internet.', mtError, [mbOK], 0); 
    end
  end
  Memo1.Text     := NMHTTP1.Body; 
  Memo1.SelStart := 0
  GetMem(FT, Length(SearchString) + 1); 
  StrPCopy(FT, SearchString); 
  BuffLen := Memo1.GetTextLen + 1
  GetMem(Buff, BuffLen); 
  Memo1.GetTextBuf(Buff, BuffLen); 
  P := Buff + Memo1.SelStart + Memo1.SelLength; 
  P := StrPos(P, FT); 
  if P = nil then MessageBeep(0
  else 
  begin 
    Memo1.SelStart  := P - Buff; 
    Memo1.SelLength := Length(SearchString); 
  end
  StringLength := Memo1.SelLength; 
  StartPos     := Memo1.SelStart + StringLength; 
  tempint      := StartPos; 
  InetIP       := ''
  while ((Buff[TempInt] in ['0'..'9']) or 
    (Buff[TempInt] = '.')) do 
  begin 
    InetIP  := InetIP + Buff[TempInt]; 
    tempint := tempint + 1
  end
  FreeMem(FT, Length(SearchString) + 1); 
  FreeMem(Buff, BuffLen); 
  Edit1.Text := InetIP; 
end

end.



Quelle: www.swissdelphicenter.ch
Talbot Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44

Win 2000, Win98, WinXP Prof, Linux(Suse, Gentoo, Debian, RedHat)
D6 Enterprise
BeitragVerfasst: Mi 20.08.03 12:40 
Hmm ich bekomm die nachricht:
[Fehler] Unit1.pas(42): Undefinierter Bezeichner: 'NMHTTP1'

NMHTTP ist ne unit oder?

Zu hülf :)

...

Okay. es ist ne Komponente. hab ich schon gefunden. Funzt aber immer noch nicht. kann das daran liegen das ich hinter nem Proxy sitze?

...

hat sich auch schon erledigt :-D
man kann die proxyeinstellungen ja in NMHTTP1 festlegen.

Moderiert von user profile iconTino: Beiträge zusammen geführt.
oPPi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66

MS Win 7 Pro, WinXP Pro
D3 Pro, TurboDelhi, Kylix 3 Pro
BeitragVerfasst: Do 21.08.03 21:51 
Hy,

warum son langer code, ich sitzte auch hinter einem router
und bekomme mit nachfolgenden genauso die Internet-IP:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
const
  sURL = 'http://www.whatismyip.com';
  sSearchText = 'your ip is';
var
  sResult: string;
  sIP    : string;
begin
  try
    HTTP.Get(sURL); //Komponente aus der FastNet-Komponentenleiste
    sResult := http.Body;
    sResult := LowerCase(sResult);
    sIP := Copy(sResult, pos(sSearchText, sResult) + Length(sSearchText) + 1,pos(' ', Copy(sResult, pos(sSearchText, sResult) + Length(sSearchText) + 1, length(sResult))) -1 );
    txt_WebIP.Text := sIP; // Hier ist nun die Internet-IP
  except
    ShowMessage('Internet IP konnte nicht gefunden werden !!!');
  end;
Talbot Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44

Win 2000, Win98, WinXP Prof, Linux(Suse, Gentoo, Debian, RedHat)
D6 Enterprise
BeitragVerfasst: Mo 25.08.03 10:00 
Hey Prima!
Ich bin immer für Optimierungen offen!