IP Address and download

H

Hilton

Hi,

I have a customer reporting that:

IPHostEntry hostEntry = Dns.GetHostByName (Dns.GetHostName ());
result = hostEntry.AddressList [0].ToString ();

only gives 127.0.0.1 and it is the only addr in the list. However, the same
EXE manages to download a file from a web site with no problem (his PDA's IE
works fine too). So, my questions are:
1. Even though the PDA is connected, why is he (only) getting 127.0.0.1,
2. If he is (only) getting 127.0.0.1, how can the download work, and
lastly.
3. By using the code above and checking for 127.0.0.1, I thought that was
the correct way to check for connectivity, clearly it isn't. Is there
another way that works 100%?

Two interfaces? One reports 127.0.0.1, other one doesn't?

Thanks,

Hilton
 
P

Paul G. Tobey [eMVP]

GetHostName() is probably returning "localhost" and that's probably mapping
to the loopback IP address. Even if you *have* a valid IP address, you
won't necessarily be connected. For some types of connections, that might
be true, GPRS, for example, but you can have a statically-assigned IP on
your 802.11 wireless card and be 200 miles from the nearest access point...

Paul T.
 
H

Hilton

Paul,

Thanks for the reply. in this case, it is kinda the reverse; i.e. no valid
IP address (only 127.0.0.1), but the download works fine. I'm trying to
have a method:

HasInternetConnection()

that works for this case. Currently since it only sees 127.0.0.1 it thinks
that it is not connected and therefore won't even start the download.

Thanks,

Hilton


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:%[email protected]...
GetHostName() is probably returning "localhost" and that's probably
mapping to the loopback IP address. Even if you *have* a valid IP
address, you won't necessarily be connected. For some types of
connections, that might be true, GPRS, for example, but you can have a
statically-assigned IP on your 802.11 wireless card and be 200 miles from
the nearest access point...

Paul T.

Hilton said:
Hi,

I have a customer reporting that:

IPHostEntry hostEntry = Dns.GetHostByName (Dns.GetHostName ());
result = hostEntry.AddressList [0].ToString ();

only gives 127.0.0.1 and it is the only addr in the list. However, the
same EXE manages to download a file from a web site with no problem (his
PDA's IE works fine too). So, my questions are:
1. Even though the PDA is connected, why is he (only) getting 127.0.0.1,
2. If he is (only) getting 127.0.0.1, how can the download work, and
lastly.
3. By using the code above and checking for 127.0.0.1, I thought that
was the correct way to check for connectivity, clearly it isn't. Is
there another way that works 100%?

Two interfaces? One reports 127.0.0.1, other one doesn't?

Thanks,

Hilton
 
P

Paul G. Tobey [eMVP]

That's what I'm saying: you aren't asking for an address that will tell you
anything. You could try using DNS to resolve something like
www.microsoft.com to tell if you have an Internet connection, although
that's not fool-proof, either (a local DNS server might know that name and
its corresponding IP address without actually being able to reach it). *No*
network function that returns an IP address can be used to test for Internet
connectivity with 100% reliability.

What do you do if there isn't a connection? Couldn't you try to connect to
the server you want to download from and decide if you're connected based on
whether that works or not?

Paul T.

Hilton said:
Paul,

Thanks for the reply. in this case, it is kinda the reverse; i.e. no
valid IP address (only 127.0.0.1), but the download works fine. I'm
trying to have a method:

HasInternetConnection()

that works for this case. Currently since it only sees 127.0.0.1 it
thinks that it is not connected and therefore won't even start the
download.

Thanks,

Hilton


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:%[email protected]...
GetHostName() is probably returning "localhost" and that's probably
mapping to the loopback IP address. Even if you *have* a valid IP
address, you won't necessarily be connected. For some types of
connections, that might be true, GPRS, for example, but you can have a
statically-assigned IP on your 802.11 wireless card and be 200 miles from
the nearest access point...

Paul T.

Hilton said:
Hi,

I have a customer reporting that:

IPHostEntry hostEntry = Dns.GetHostByName (Dns.GetHostName ());
result = hostEntry.AddressList [0].ToString ();

only gives 127.0.0.1 and it is the only addr in the list. However, the
same EXE manages to download a file from a web site with no problem (his
PDA's IE works fine too). So, my questions are:
1. Even though the PDA is connected, why is he (only) getting
127.0.0.1,
2. If he is (only) getting 127.0.0.1, how can the download work, and
lastly.
3. By using the code above and checking for 127.0.0.1, I thought that
was the correct way to check for connectivity, clearly it isn't. Is
there another way that works 100%?

Two interfaces? One reports 127.0.0.1, other one doesn't?

Thanks,

Hilton
 
H

Hilton

Thanks for the reply Paul. The way the app is currently setup is to get an
IPAddress every second or so, and show the state to the user. Also, it will
disable the download button if the IP Address is 127.0.0.1. Thanks for your
input, I'll take another look at the logic and figure out something that can
handle this case.

I'm still not sure why I only get 127.0.0.1 returned to me, but a download
works fine.

Hilton


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
That's what I'm saying: you aren't asking for an address that will tell
you anything. You could try using DNS to resolve something like
www.microsoft.com to tell if you have an Internet connection, although
that's not fool-proof, either (a local DNS server might know that name and
its corresponding IP address without actually being able to reach it).
*No* network function that returns an IP address can be used to test for
Internet connectivity with 100% reliability.

What do you do if there isn't a connection? Couldn't you try to connect
to the server you want to download from and decide if you're connected
based on whether that works or not?

Paul T.

Hilton said:
Paul,

Thanks for the reply. in this case, it is kinda the reverse; i.e. no
valid IP address (only 127.0.0.1), but the download works fine. I'm
trying to have a method:

HasInternetConnection()

that works for this case. Currently since it only sees 127.0.0.1 it
thinks that it is not connected and therefore won't even start the
download.

Thanks,

Hilton


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> wrote in message news:%[email protected]...
GetHostName() is probably returning "localhost" and that's probably
mapping to the loopback IP address. Even if you *have* a valid IP
address, you won't necessarily be connected. For some types of
connections, that might be true, GPRS, for example, but you can have a
statically-assigned IP on your 802.11 wireless card and be 200 miles
from the nearest access point...

Paul T.

Hi,

I have a customer reporting that:

IPHostEntry hostEntry = Dns.GetHostByName (Dns.GetHostName ());
result = hostEntry.AddressList [0].ToString ();

only gives 127.0.0.1 and it is the only addr in the list. However, the
same EXE manages to download a file from a web site with no problem
(his PDA's IE works fine too). So, my questions are:
1. Even though the PDA is connected, why is he (only) getting
127.0.0.1,
2. If he is (only) getting 127.0.0.1, how can the download work, and
lastly.
3. By using the code above and checking for 127.0.0.1, I thought that
was the correct way to check for connectivity, clearly it isn't. Is
there another way that works 100%?

Two interfaces? One reports 127.0.0.1, other one doesn't?

Thanks,

Hilton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top