Indy 8.x를 이용하여 프로그래밍하다가 찾아낸 것인데, 접속하지 않고 자신의 local ip를 모두 구해 낼 수 있습니다.
방법은 Indy에는 GStack이라는 글로벌 변수가 있는데, 이 변수 내에 LocalAddresses라는 TStings 개체가 해당 시스템의 모든 local ip를 표현합니다.
따라서,
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if ( GStack == NULL ) return;
for ( int i = 0; i < GStack->LocalAddresses->Count; i++ )
// 아시겠지만 참고삼아, lan card를 여러개 설치하면 하나 이상의 ip를 가지게 됩니다. ^^;
{
Memo1->Lines->Add (GStack->LocalAddresses->Strings [i]);
// GStack->LocalAddresses->Strings [i] : 이게 local ip
}
}
아시겠지만 참고삼아, 연결하였을 경우의 local ip, remote ip는
(아래는 TIdTCPServer, TIdTCPClient의 예입니다.)
서버의 경우,
AThread->Connection->Binding->IP : local ip
AThread->Connection->Binding->PeerIP : remote ip
클라이언트의 경우
tcpClient1->Binding->IP : local ip
tcpClient1->Binding->PeerIP : remote ip
|