2008 Warning in my code gethostbyname

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 44
Reputation: smelf1 is an unknown quantity at this point 
Solved Threads: 0
smelf1 smelf1 is offline Offline
Light Poster

2008 Warning in my code gethostbyname

 
0
  #1
Jan 15th, 2009
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.


  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: 2008 Warning in my code gethostbyname

 
0
  #2
Jan 15th, 2009
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.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 44
Reputation: smelf1 is an unknown quantity at this point 
Solved Threads: 0
smelf1 smelf1 is offline Offline
Light Poster

Re: 2008 Warning in my code gethostbyname

 
0
  #3
Jan 15th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: 2008 Warning in my code gethostbyname

 
0
  #4
Jan 15th, 2009
You didn't said I want just IPv4
To get it
  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.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 44
Reputation: smelf1 is an unknown quantity at this point 
Solved Threads: 0
smelf1 smelf1 is offline Offline
Light Poster

Re: 2008 Warning in my code gethostbyname

 
0
  #5
Jan 15th, 2009
right i tried this

  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: 2008 Warning in my code gethostbyname

 
0
  #6
Jan 15th, 2009
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!!!!!!!!!
  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.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 44
Reputation: smelf1 is an unknown quantity at this point 
Solved Threads: 0
smelf1 smelf1 is offline Offline
Light Poster

Re: 2008 Warning in my code gethostbyname

 
0
  #7
Jan 15th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: 2008 Warning in my code gethostbyname

 
0
  #8
Jan 15th, 2009
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!
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: 2008 Warning in my code gethostbyname

 
0
  #9
Jan 15th, 2009
split it by :
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 44
Reputation: smelf1 is an unknown quantity at this point 
Solved Threads: 0
smelf1 smelf1 is offline Offline
Light Poster

Re: 2008 Warning in my code gethostbyname

 
0
  #10
Jan 15th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC