InetAddress.getByname vs ping Options

421 views
Skip to first unread message

aad

unread,
Nov 30, 2010, 10:52:07 PM11/30/10
to android-platform
Hi,
I need to resolve an host address to ip.
My android device can ping to the hostname only to resolve the host
to
IP . But when I use InetAddress.getByname, it throws an exception.

An excerpt of hyper terminal trace is below.


Please help me resolve this issue by letteing me know which api i
must
use as ping is only having DNS resolution but not successful packet
transmission.


Trace:


# ping -c 2 www.google.com
PING www.l.google.com (209.85.132.104) 56(84) bytes of data.
^C
^C


--- www.l.google.com ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1006ms


# #
#
# # ping -c 2 www.yahoo.com
PING any-fp.wa1.b.yahoo.com (67.195.160.76) 56(84) bytes of data.
^C
--- any-fp.wa1.b.yahoo.com ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1006ms


# ping -c 2 www.starwave.com
PING starwave.com (199.181.132.250) 56(84) bytes of data.


--- starwave.com ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1007ms


#
#
The trace of exception by InetAddress.getByname:
------------------------------------------------------
W/Server( 1122): Connection error: W/Server( 1122):
java.net.UnknownHostException: starwave.com W/Server( 1122): at
java.net.InetAddress.lookupHostByName(InetAddress.java:504) W/
Server( 1122): at
java.net.InetAddress.getAllByNameImpl(InetAddress.java:280) W/
Server( 1122): at java.net.InetAddress.getByName(InetAddress.java:
310)
W/Server( 1122): at android..config.Config.getSLPHost(Config.java:
169)
W/Server( 1122): at com.android.server.Server.run(Server.java:211) W/
Server( 1122): at java.lang.Thread.run(Thread.java:1096)


Thanks in advance for your time

P.S. The same question was also posted at
http://groups.google.com/group/android-developers/browse_thread/thread/16ae9f0a3da2f8d5

Regards,
GSA

Nirjon

unread,
Dec 1, 2010, 3:57:19 PM12/1/10
to android-...@googlegroups.com
Hi,

How did you call the InetAddress.getByName() method? Could you paste that part of your source code?

btw. I tried to go to www.starwave.com (with my laptop's browser) and it seems like the website does not exist. And when I use (199.181.132.250) in my browser it goes to go.com

Shahriar Nirjon
University of Virginia.


--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
Nirjon.

aad

unread,
Dec 1, 2010, 11:40:09 PM12/1/10
to android-platform
Hi,
The code is below: I tried google too

/**
* Returns IP address given hostname, handles exceptions
*/
public void getIPAddr () {

try {
java.net.InetAddress inetAddr1[] =
java.net.InetAddress.getAllByName("google.com") ;
Log.d(TAG, "TAG - Inet address google.com - getAllByName" +
inetAddr1[0] );
} catch (java.net.UnknownHostException e1) {
Log.d(TAG, "TAG - Inet address error google.com -
getAllByName" );
}

try {
java.net.InetAddress inetAddr2 =
java.net.InetAddress.getByName("google.com") ;
Log.d(TAG, "TAG - Inet address google.com - getByName" +
inetAddr2 );
} catch (java.net.UnknownHostException e1) {
Log.d(TAG, "TAG - Inet address error google.com -
getByName" );
}
finally {
Log.d(TAG, "TAG - OUT OF getIPAddr" );
}
}

***********************************
Here only the catch block is getting executed. Trace excerpt
D/SC( 1123): TAG - Addr error google.com - getAllByName
D/SC( 1123): TAG - Addr error google.com - getByName
D/SC( 1123): TAG - OUT OF getIPAddr

**********************************

Regards,
Aad

On Dec 2, 1:57 am, Nirjon <nir...@gmail.com> wrote:
> Hi,
>
> How did you call the InetAddress.getByName() method? Could you paste that
> part of your source code?
>
> btw. I tried to go towww.starwave.com(with my laptop's browser) and it
> seems like the website does not exist. And when I use (199.181.132.250) in
> my browser it goes to go.com.
>
> Shahriar Nirjon
> University of Virginia.
>
>
>
>
>
> On Tue, Nov 30, 2010 at 7:52 PM, aad <gsa....@gmail.com> wrote:
> > Hi,
> > I need to resolve an host address to ip.
> > My android device can ping to the hostname only to resolve the host
> > to
> > IP . But when I use InetAddress.getByname, it throws an exception.
>
> > An excerpt of hyper terminal trace is below.
>
> > Please help me resolve this issue by letteing me know which api i
> > must
> > use as ping is only having DNS resolution but not successful packet
> > transmission.
>
> > Trace:
>
> > # ping -c 2www.google.com
> > PINGwww.l.google.com(209.85.132.104) 56(84) bytes of data.
> > ^C
> > ^C
>
> > ---www.l.google.comping statistics ---
> >http://groups.google.com/group/android-developers/browse_thread/threa...
>
> > Regards,
> > GSA
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-platform" group.
> > To post to this group, send email to android-...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-platfo...@googlegroups.com<android-platform%2Bunsubscrib­e...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-platform?hl=en.
>
> --
> Nirjon.- Hide quoted text -
>
> - Show quoted text -

Nirjon

unread,
Dec 2, 2010, 7:12:15 PM12/2/10
to android-...@googlegroups.com
Two things:

1. Why in your trace excerpt it is showing "TAG - Addr error google.com - getAllByName" whereas in your source you are printing "TAG - Inet address error google.com -getAllByName" ?? Are you running the correct program?

2. You code is OK to me. I think you have a problem with internet connection. Could you try "localhost" instead of "google.com"?

Bests,
Shahriar Nirjon
University of Virginia 


To unsubscribe from this group, send email to android-platfo...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
Nirjon.

aad

unread,
Dec 3, 2010, 4:45:01 AM12/3/10
to android-platform
Hi,
my problem was solved when I included the code after my application
started. Thank you for your vital clues. But, I donot know how to
findout which manifest file my application uses.

Regards,
Aad
> > > btw. I tried to go towww.starwave.com(withmy laptop's browser) and it
> > > seems like the website does not exist. And when I use (199.181.132.250)
> > in
> > > my browser it goes to go.com.
>
> > > Shahriar Nirjon
> > > University of Virginia.
>
> > > On Tue, Nov 30, 2010 at 7:52 PM, aad <gsa....@gmail.com> wrote:
> > > > Hi,
> > > > I need to resolve an host address to ip.
> > > > My android device can ping to the hostname only to resolve the host
> > > > to
> > > > IP . But when I use InetAddress.getByname, it throws an exception.
>
> > > > An excerpt of hyper terminal trace is below.
>
> > > > Please help me resolve this issue by letteing me know which api i
> > > > must
> > > > use as ping is only having DNS resolution but not successful packet
> > > > transmission.
>
> > > > Trace:
>
> > > > # ping -c 2www.google.com
> > > > PINGwww.l.google.com(209.85.132.104) 56(84) bytes of data.
> > > > ^C
> > > > ^C
>
> > > > ---www.l.google.compingstatistics ---
Reply all
Reply to author
Forward
0 new messages