How do I get a computer's name and IP address using VB.NET?

后端 未结 10 1017
春和景丽
春和景丽 2020-12-09 11:32

How can i get ip address of system by sending mac ip address as input using vb.net coding?

相关标签:
10条回答
  • 2020-12-09 12:36

    Thanks Shuwaiee

    I made a slight change though as using it in a Private Sub already.

    Dim 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 & vbCrLf & "IP Address: " & strIPAddress)
    

    But also made a change to the way the details are displayed so that they can show on seperate lines using & vbCrLf &

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

    Hope this helps someone.

    0 讨论(0)
  • 2020-12-09 12:36
        Public strHostName As String
        Public strIPAddress As String
        strHostName = System.Net.Dns.GetHostName()
        strIPAddress = System.Net.Dns.GetHostEntry(strHostName).AddressList(0).ToString()
        MessageBox.Show("Host Name: " & strHostName & "; IP Address: " & strIPAddress)
    
    0 讨论(0)
  • 2020-12-09 12:37
    Imports System.Net
    
    Module MainLine
        Sub Main()
            Dim hostName As String = Dns.GetHostName
            Console.WriteLine("Host Name : " & hostName & vbNewLine)
            For Each address In Dns.GetHostEntry(hostName).AddressList()
                Select Case Convert.ToInt32(address.AddressFamily)
                    Case 2
                        Console.WriteLine("IP Version 4 Address: " & address.ToString)
                    Case 23
                        Console.WriteLine("IP Version 6 Address: " & address.ToString)
                End Select
            Next
            Console.ReadKey()
        End Sub
    End Module
    
    0 讨论(0)
  • 2020-12-09 12:37
    Label12.Text = "My ID : " + System.Net.Dns.GetHostByName(Net.Dns.GetHostName()).AddressList(0).ToString()
    

    use this code, without any variable

    0 讨论(0)
提交回复
热议问题