 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Roberto Meneghini Guest
|
Posted: Wed Sep 27, 2006 10:35 pm Post subject: GStack |
|
|
Hello,
I'm trying to access the "LocalAddresses" property to find out the IP
address of the network adapters installed in a computer. It always return
0.0.0.0. However, HostName does return the correct name.
I'm using Delphi 2006 .NET. I've dropped a TIdTCPServer on my form.
Thanks,
Roberto |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Sep 27, 2006 10:46 pm Post subject: Re: GStack |
|
|
"Roberto Meneghini" <rmeneghini (AT) separationsystems (DOT) com> wrote in message
news:451ab664$1 (AT) newsgroups (DOT) borland.com...
| Quote: | I'm trying to access the "LocalAddresses" property to find out the
IP address of the network adapters installed in a computer. It always
return 0.0.0.0.
|
Then you do not have any adapters available.
| Quote: | However, HostName does return the correct name.
|
That has nothing to do with adapters. The HostName is the name of the
machine itself, and is not dependant on any adapters.
Gambit |
|
| Back to top |
|
 |
Roberto Meneghini Guest
|
Posted: Wed Sep 27, 2006 11:37 pm Post subject: Re: GStack |
|
|
Hello Gambit,
I do have at least one adapter installed in my computer. I can see all the
information when I use "ipconfig " from the command prompt or via windows
"Show all connections". Any suggestions?
Thanks,
Roberto
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:451ab98e (AT) newsgroups (DOT) borland.com...
| Quote: |
"Roberto Meneghini" <rmeneghini (AT) separationsystems (DOT) com> wrote in message
news:451ab664$1 (AT) newsgroups (DOT) borland.com...
I'm trying to access the "LocalAddresses" property to find out the
IP address of the network adapters installed in a computer. It always
return 0.0.0.0.
Then you do not have any adapters available.
However, HostName does return the correct name.
That has nothing to do with adapters. The HostName is the name of the
machine itself, and is not dependant on any adapters.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Sep 28, 2006 12:25 am Post subject: Re: GStack |
|
|
"Roberto Meneghini" <rmeneghini (AT) separationsystems (DOT) com> wrote in message
news:451ac4e5 (AT) newsgroups (DOT) borland.com...
| Quote: | I do have at least one adapter installed in my computer. I can see all
the information when I use "ipconfig " from the command prompt or
via windows "Show all connections".
|
Then there is no way the LocalAddresses property could be giving you
'0.0.0.0' and nothing else, without throwing an exception. What does your
actual code look like?
Gambit |
|
| Back to top |
|
 |
Roberto Meneghini Guest
|
Posted: Thu Sep 28, 2006 1:28 am Post subject: Re: GStack |
|
|
Hello Gambit,
This is the code that I wrote inside an "OnClick" event. As I mentioned the
only INDY10 component that I've dropped on my form is "TIdTCPServer". It is
listening at port 500 and it is active.
Regards,
Roberto
var
I:Integer;
Item: TListItem;
begin
lvLog.Items.BeginUpdate;
for I := 0 to GStack.LocalAddresses.Count - 1 do
begin
Item := lvLog.Items.Add;
Item.Caption(GStack.LocalAddresses.Strings[0]);
end;
lvLog.Items.EndUpdate;
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:451ad234$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
"Roberto Meneghini" <rmeneghini (AT) separationsystems (DOT) com> wrote in message
news:451ac4e5 (AT) newsgroups (DOT) borland.com...
I do have at least one adapter installed in my computer. I can see all
the information when I use "ipconfig " from the command prompt or
via windows "Show all connections".
Then there is no way the LocalAddresses property could be giving you
'0.0.0.0' and nothing else, without throwing an exception. What does your
actual code look like?
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Sep 28, 2006 4:39 am Post subject: Re: GStack |
|
|
"Roberto Meneghini" <rmeneghini (AT) separationsystems (DOT) com> wrote in message
news:451adee5$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Item.Caption(GStack.LocalAddresses.Strings[0]);
|
Caption is a property, not a function.
Every time you access the LocalAddress or LocalAddresses property, the list
is re-populated, so you should only access the property once, not over and
over. Also, every time your loop is adding a new ListView item, it is
always assigning the first address in the list as the Caption instead of
using the current address from the loop.
Use this code instead:
var
I: Integer;
Item: TListItem;
Addresses: TIdStrings;
begin
lvLog.Items.BeginUpdate;
try
Addresses := GStack.LocalAddresses;
for I := 0 to Pred(Addresses.Count) do
begin
Item := lvLog.Items.Add;
Item.Caption := Addresses[I];
end;
finally
lvLog.Items.EndUpdate;
end;
end;
| Quote: | As I mentioned the only INDY10 component that I've
dropped on my form is "TIdTCPServer".
|
Using any Indy component will initialize GStack at runtime.
| Quote: | It is listening at port 500 and it is active.
|
That has no effect whatsoever on GStack's ability to get the local
addresses.
Gambit |
|
| Back to top |
|
 |
Roberto Meneghini Guest
|
Posted: Thu Sep 28, 2006 4:59 am Post subject: Re: GStack |
|
|
Thank you Gambit. Unfortunately it still shows "0.0.0.0". I have tested the
application in two other computers just in case. All the computers are
running XP SP2. Does it make any difference if the target application is a
VCL.NET ? Is there a patch that I need to installed? I'm using Indy10 that
ships with BDS2006. I have installed update 2 of BDS2006.
Regards,
Roberto
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:451b0c44$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
"Roberto Meneghini" <rmeneghini (AT) separationsystems (DOT) com> wrote in message
news:451adee5$1 (AT) newsgroups (DOT) borland.com...
Item.Caption(GStack.LocalAddresses.Strings[0]);
Caption is a property, not a function.
Every time you access the LocalAddress or LocalAddresses property, the
list
is re-populated, so you should only access the property once, not over and
over. Also, every time your loop is adding a new ListView item, it is
always assigning the first address in the list as the Caption instead of
using the current address from the loop.
Use this code instead:
var
I: Integer;
Item: TListItem;
Addresses: TIdStrings;
begin
lvLog.Items.BeginUpdate;
try
Addresses := GStack.LocalAddresses;
for I := 0 to Pred(Addresses.Count) do
begin
Item := lvLog.Items.Add;
Item.Caption := Addresses[I];
end;
finally
lvLog.Items.EndUpdate;
end;
end;
As I mentioned the only INDY10 component that I've
dropped on my form is "TIdTCPServer".
Using any Indy component will initialize GStack at runtime.
It is listening at port 500 and it is active.
That has no effect whatsoever on GStack's ability to get the local
addresses.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Sep 28, 2006 5:57 am Post subject: Re: GStack |
|
|
"Roberto Meneghini" <rmeneghini (AT) separationsystems (DOT) com> wrote in message
news:451b104e (AT) newsgroups (DOT) borland.com...
| Quote: | Does it make any difference if the target application is a VCL.NET ?
|
Yes, that would make all of the difference.
Under .NET, Indy uses the TIdStackDotNet class. The
TIdStackDotNet.PopulateLocalAddresses() method calls the
System.Net.Dns.GetHostByAddress() method to get the address list.
However, it is passing the System.Net.IPAddress.Any property as the address
for GetHostByAddress() to resolve. IPAddress.Any is the same as '0.0.0.0'.
I do not know if GetHostByAddress('0.0.0.0') is valid in .NET, but it is
certainly not valid in Win32 and Linux. Under Win32 and Linux, Indy uses
the socket API gethostname() and gethostbyname() functions instead. Why
Indy is not using System.Net.Dns.GetHostName() and
System.Net.Dns.GetHostByName() under .NET, I do not know.
Gambit |
|
| Back to top |
|
 |
Roberto Meneghini Guest
|
Posted: Thu Sep 28, 2006 6:46 am Post subject: Re: GStack |
|
|
That solved the problem. I used
System.Net.Dns.GetHostByName(GStack.HostName).AddressList and was able to
list the IP address of the adapters.
Thanks for pointing me into the right direction,
Roberto
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:451b1e98$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
"Roberto Meneghini" <rmeneghini (AT) separationsystems (DOT) com> wrote in message
news:451b104e (AT) newsgroups (DOT) borland.com...
Does it make any difference if the target application is a VCL.NET ?
Yes, that would make all of the difference.
Under .NET, Indy uses the TIdStackDotNet class. The
TIdStackDotNet.PopulateLocalAddresses() method calls the
System.Net.Dns.GetHostByAddress() method to get the address list.
However, it is passing the System.Net.IPAddress.Any property as the
address
for GetHostByAddress() to resolve. IPAddress.Any is the same as
'0.0.0.0'.
I do not know if GetHostByAddress('0.0.0.0') is valid in .NET, but it is
certainly not valid in Win32 and Linux. Under Win32 and Linux, Indy uses
the socket API gethostname() and gethostbyname() functions instead. Why
Indy is not using System.Net.Dns.GetHostName() and
System.Net.Dns.GetHostByName() under .NET, I do not know.
Gambit
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|