954,153 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

2008 Warning in my code gethostbyname

Hi when i use the following code i get a warning
'Public Shared Function GetHostByName(hostName As String) As System.Net.IPHostEntry' is obsolete: 'GetHostByName is obsoleted for this type, please use GetHostEntry instead.

Dim host As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName) 'gets the machines current IP


now the code works and shows me the ip

smelf1
Light Poster
44 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

obsolete attribute means this method is old, and another one is used (GetHostEntry in your case)!
We use this attribute to tell developers who use our libraries that this method no longer use and use an alternative (the new one) + telling the compiler to raise warning or error if it used!
Understood?

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

ah yeah but its telling me to use gethostentry but if i use that it displays the ipv6 address and not the normal ipv4 one i need

smelf1
Light Poster
44 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

You didn't said I want just IPv4
To get it

dim host as IPHostEntry 
            dim hostname  as string 
hostname = "lmlmlaa";
            host = Dns.GetHostEntry(hostname)
For Each ip As IPAddress In host.AddressList
                if ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork 
                    MessageBox.Show(ip.ToString())
        Next

I don't know VB.NET, I tried to convert it to VB.NET as much as I can.

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

right i tried this

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myip As String = System.Net.Dns.GetHostAddresses(My.Computer.Name)(1).ToString().Trim
        ComboBox1.Items.Add(myip)
    End Sub


but it returen fe80::5efe:192.168.0.19%10 i just wanted 192.168.0.19 how do i get it to show that and not this fe80::5efe:192.168.0.19%10

smelf1
Light Poster
44 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

Please concentrate in my answer and try this code, don't get me another pieces of code which I didn't write and say it doesn't work!!!!!!!!!

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dim host as IPHostEntry 
dim hostname  as string 
hostname =  My.Computer.Name
host = Dns.GetHostEntry(hostname)
For Each ip As IPAddress In host.AddressList
if ip.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork 
ComboBox1.Items.Add(ip)
end if
Next
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

it returns 3 items,

ipv6 fe80::3894:6b0e:ed6c:7a1c%8
fe80::5efe:192.168.0.19%10
and what i need
192.168.0.19

how do i get it to only retung the last bit?

smelf1
Light Poster
44 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

It doesn't return 3 items, seem you don't care! I tried my code before posting it works fine. I won't go on in this thread.
Excuse me!

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

split it by : ;)

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

excuse me but when i run your code it returns exactly what i posted above, and this is on a vista machine

smelf1
Light Poster
44 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

Hmmn. I only get one entry... but I don't have IPV6 enabled either.

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

hum mayby i need an if statement saying not InterNetworkv6 instead of internetwork, as ipv6 was on by default on my vista.

smelf1
Light Poster
44 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

Smelf did you get this? If not then disable ipv6 on your machine and I think his code works fine

http://wiki.williams.edu/download/attachments/17035/Disable_IPV6_Vista.pdf

rapture
Posting Whiz in Training
294 posts since Jul 2007
Reputation Points: 155
Solved Threads: 41
 

Smelf did you get this? If not then disable ipv6 on your machine and I think his code works fine

http://wiki.williams.edu/download/attachments/17035/Disable_IPV6_Vista.pdf


Hi Rapture,

Thanks for that.

Regards
Smelf1

smelf1
Light Poster
44 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

no problem, let us know if it works

rapture
Posting Whiz in Training
294 posts since Jul 2007
Reputation Points: 155
Solved Threads: 41
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You