How can i get ip address of system by sending mac ip address as input using vb.net coding?
Use the My Class :)
My.Computer.Name
as for the IP address quick google search
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
Shows the Computer Name, Use a Button to call it
Dim strHostName As String
strHostName = System.Net.Dns.GetHostName(). MsgBox(strHostName)
Shows the User Name, Use a Button to call it
If TypeOf My.User.CurrentPrincipal Is Security.Principal.WindowsPrincipal Then
Dim parts() As String = Split(My.User.Name, "\") Dim username As String = parts(1) MsgBox(username) End If
For IP Address its little complicated, But I try to explain as much as I can. First write the next code, before Form1_Load but after import section
Public Class Form1
Dim mem As String 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() mem = strIPAddress MessageBox.Show("IP Address: " & strIPAddress) End Sub
Then in Form1_Load Section just call it
GetIPAddress()
Result: On form load it will show a msgbox along with the IP address, for put into Label1.text or some where else play with the code.
Dim ipAddress As IPAddress
Dim ipHostInfo As IPHostEntry = Dns.Resolve(Dns.GetHostName())
ipAddress = ipHostInfo.AddressList(0)
Here is Example for this. In this example we can get IP address of our given host name.
Dim strHostName As String = "jayeshsorathia.blogspot.com"
'string strHostName = "www.microsoft.com";
' Get DNS entry of specified host name
Dim addresses As IPAddress() = Dns.GetHostEntry(strHostName).AddressList
' The DNS entry may contains more than one IP addresses.
' Iterate them and display each along with the type of address (AddressFamily).
For Each address As IPAddress In addresses
Response.Write(String.Format("{0} = {1} ({2})", strHostName, address, address.AddressFamily))
Response.Write("<br/><br/>")
Next
Private Function GetIPv4Address() As String
GetIPv4Address = String.Empty
Dim strHostName As String = System.Net.Dns.GetHostName()
Dim iphe As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(strHostName)
For Each ipheal As System.Net.IPAddress In iphe.AddressList
If ipheal.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork Then
GetIPv4Address = ipheal.ToString()
End If
Next
End Function
IP Version 4 Only ...
Imports System.Net
Module MainLine
Sub Main()
Dim hostName As String = Dns.GetHostName
Console.WriteLine("Host Name: " & hostName & vbNewLine)
Console.WriteLine("IP Version 4 Address(es):")
For Each address In Dns.GetHostEntry(hostName).AddressList().
Where(Function(p) p.AddressFamily = Sockets.AddressFamily.InterNetwork)
Console.WriteLine(vbTab & address.ToString)
Next
Console.ReadKey()
End Sub
End Module