Click here to Skip to main content
15,904,652 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,

Can someone tell me how I can find the IP address of a website instead of my local IP?

i have the following code:

VB
Try
           Dim ipEntry As IPHostEntry = Dns.GetHostByName(TextBox3.Text)
           Dim IpAddr As IPAddress() = ipEntry.AddressList

           TextBox3.Text = IpAddr(0).ToString()
           Dim hostname As IPHostEntry = Dns.GetHostEntry(TextBox3.Text)
           Dim ip As IPAddress() = hostname.AddressList
           TextBox3.Text = ip(0).ToString()
       Catch ex As Exception
       End Try


This keeps bringing up my own IP address in 'TextBox3'.

What I want to know is, if the user writes 'www.website.com' in 'TextBox1' how can I ask vb to go and get the IP address of 'www.website.com' and display in 'TextBox3'?

thanks in advance for any help given
Posted
Updated 19-Aug-10 4:53am
v2
Comments
Dalek Dave 19-Aug-10 10:53am    
Edited for Readability, Grammar and Code Block.

1 solution

Actually the code you have is good you just seem to have over done it.
The first 3 lines seem to work fine (Although GetHostByName is obsolete). Then you ask the second 3 lines to resolve an IP address which fails. All you need is:
Dim hostname As IPHostEntry = Dns.GetHostEntry(TextBox3.Text)
Dim ip As IPAddress() = hostname.AddressList
TextBox3.Text = ip(0).ToString()
 
Share this answer
 
Comments
hamza_786 19-Aug-10 11:20am    
hi,

i think what you have given me is right but there is a problem when displaying the ip address. the ip address looks like this when displayed in textbox3: fe80::c1ee:b98a:13a0:a1a6%11
Nyarost 19-Aug-10 11:23am    
It is IPv6 address.
hamza_786 19-Aug-10 11:31am    
how can i fix the above?
rhuiden 19-Aug-10 11:31am    
Thats right. It is IPv6. I don't have v6 turned on at the moment, but I think if you check the list of addresses one of them will be v4.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900