943,699 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 3346
  • VB.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Jan 15th, 2009
0

2008 Warning in my code gethostbyname

Expand Post »
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.


VB.NET Syntax (Toggle Plain Text)
  1. 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
Reputation Points: 10
Solved Threads: 0
Light Poster
smelf1 is offline Offline
44 posts
since Mar 2008
Jan 15th, 2009
0

Re: 2008 Warning in my code gethostbyname

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?
Last edited by Ramy Mahrous; Jan 15th, 2009 at 8:45 am.
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Jan 15th, 2009
0

Re: 2008 Warning in my code gethostbyname

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
Reputation Points: 10
Solved Threads: 0
Light Poster
smelf1 is offline Offline
44 posts
since Mar 2008
Jan 15th, 2009
0

Re: 2008 Warning in my code gethostbyname

You didn't said I want just IPv4
To get it
vb.net Syntax (Toggle Plain Text)
  1. dim host as IPHostEntry
  2. dim hostname as string
  3. hostname = "lmlmlaa";
  4. host = Dns.GetHostEntry(hostname)
  5. For Each ip As IPAddress In host.AddressList
  6. if ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork
  7. MessageBox.Show(ip.ToString())
  8. Next
I don't know VB.NET, I tried to convert it to VB.NET as much as I can.
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Jan 15th, 2009
0

Re: 2008 Warning in my code gethostbyname

right i tried this

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim myip As String = System.Net.Dns.GetHostAddresses(My.Computer.Name)(1).ToString().Trim
  3. ComboBox1.Items.Add(myip)
  4. 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
Reputation Points: 10
Solved Threads: 0
Light Poster
smelf1 is offline Offline
44 posts
since Mar 2008
Jan 15th, 2009
0

Re: 2008 Warning in my code gethostbyname

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!!!!!!!!!
vb.net Syntax (Toggle Plain Text)
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. dim host as IPHostEntry
  3. dim hostname as string
  4. hostname = My.Computer.Name
  5. host = Dns.GetHostEntry(hostname)
  6. For Each ip As IPAddress In host.AddressList
  7. if ip.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork
  8. ComboBox1.Items.Add(ip)
  9. end if
  10. Next
Last edited by Ramy Mahrous; Jan 15th, 2009 at 11:50 am.
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Jan 15th, 2009
0

Re: 2008 Warning in my code gethostbyname

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?
Reputation Points: 10
Solved Threads: 0
Light Poster
smelf1 is offline Offline
44 posts
since Mar 2008
Jan 15th, 2009
0

Re: 2008 Warning in my code gethostbyname

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!
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Jan 15th, 2009
0

Re: 2008 Warning in my code gethostbyname

split it by :
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jan 15th, 2009
0

Re: 2008 Warning in my code gethostbyname

excuse me but when i run your code it returns exactly what i posted above, and this is on a vista machine
Last edited by smelf1; Jan 15th, 2009 at 12:14 pm.
Reputation Points: 10
Solved Threads: 0
Light Poster
smelf1 is offline Offline
44 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: rotating graphics
Next Thread in VB.NET Forum Timeline: Find Text String and Output Line Numbers Text Falls on





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC