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

Recommended Answers

All 14 Replies

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?

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

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.

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

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

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?

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!

split it by : ;)

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

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

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

no problem, let us know if it works

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.