Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

Can anyone know?

how to identify computer name and ip address using vb.net code?
Posted

Try This
VB
Private Sub GetIPAddress()

Dim strHostName As String

Dim strIPAddress As String



strHostName = System.Net.Dns.GetHostName()

strIPAddress = System.Net.Dns.GetHostByName(strHostName).AddressList(0).ToString()


MessageBox.Show("Host Name: " & strHostName & "; IP Address: " & strIPAddress)

End Sub


To Get Just The IP Address Try the following

C#
string myHost = System.Net.Dns.GetHostName();
            System.Net.IPHostEntry myIPs = System.Net.Dns.GetHostEntry(myHost);
            foreach (System.Net.IPAddress myIP in myIPs.AddressList)
            {
                TextBox1.Text = myIP.ToString();
            }


One More Option Is

VB
Option Strict Off
Imports system
Imports System.Net.DNS
Public Class GetIP
Shared Function GetIPAddress() As String
Dim sam As System.Net.IPAddress
Dim sam1 As String
With system.Net.DNS.GetHostByName(system.Net.DNS.GetHostName())
    sam = New System.Net.IPAddress(.AddressList(0).Address)
    sam1 = sam.ToString
End With
GetIPAddress = sam1
End Function
    Shared Sub main()
      Dim shostname As String
      shostname = system.Net.DNS.GetHostName
      console.writeline("Name of the System is = " & shostname)
      console.writeline("Your IP address is= " & GetIPAddress)
    End Sub
 End Class


Hope this will help you
 
Share this answer
 
v2
Of a remote machine, the local machine the code is running on, or from an incoming connection to your application??
 
Share this answer
 
Comments
sathiyak 27-Feb-12 0:16am    
this question is asked by HR in my interview...i know just this question...
Dave Kreskowiak 27-Feb-12 1:11am    
Well, that's when you start asking questions to find out what the actual requirements are. The question as asked doesn't have enough detail to give any kind of accurate answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900