mario.deghetto

Visual Basic & .NET
posts - 332, comments - 79, trackbacks - 0

#4: [VB.NET] Ottenere l’indirizzo IP

Tip valido per le versioni dalla 2005 in poi.

Per ottenere l’indirizzo IP della macchina (collegata in rete) sulla quale gira il programma, ecco una buona soluzione:

Private Shared Sub NamedSub()
  Dim loip() As System.Net.IPAddress = _
    System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName)
  Dim ip As String = loip(0).ToString
  MessageBox.Show(ip)
End Sub

E’ possibile ottenere altre informazioni sulla connessione di rete leggendo questo articolo pubblicato su MSDN

Il metodo usato in Visual Basic 2003 è obsoleto e da evitare:

Dim ip As String = _
System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
.AddressList(0).ToString 

N.B.: l’istruzione deve essere scritta tutta su una singola riga

Print | posted on domenica 11 ottobre 2009 6.00 |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 6 and 6 and type the answer here:

Powered by: