### Get IP and Network Addresses

Example getting the various network addresses, using the libraries JavaObject and ByteConverter.
Dim JO As JavaObject
JO.InitializeStatic("java.net.InetAddress")
Dim objLocalHost As Object = JO.RunMethod("getLocalHost", Null)
Log("LocalHost Address: " & objLocalHost)
Output LocalHost Address: RwbL/192.168.0.7
Dim objLoopbackAddress As Object = JO.RunMethod("getLoopbackAddress", Null)
Log("Loopback Address: " & objLoopbackAddress)
Output Loopback Address: localhost/127.0.0.1
Dim JO2 As JavaObject = JO.RunMethod("getLocalHost", Null)
Dim objHostAddress As Object = JO2.RunMethod("getHostAddress", Null)
Dim ip As String = objHostAddress
Log("Host Address: " & ip)
Output Host Address: 192.168.0.7
Dim JO3 As JavaObject
JO3.InitializeStatic("java.net.NetworkInterface")
Dim network As Object = JO3.RunMethod("getByInetAddress", Array As Object(objLocalHost))
Log("Network Address:" & network)
Output Network Address:name:net0 (Qualcomm Atheros AR5BWB222 Wireless Network Adapter)
Dim JO4 As JavaObject = JO3.RunMethod("getByInetAddress", Array As Object(objLocalHost))
Dim hwa() As Byte = JO4.RunMethod("getHardwareAddress", Null)
Dim bc As ByteConverter
Dim sb As StringBuilder
sb.Initialize
sb.Append(bc.HexFromBytes(hwa))
sb.Insert(2, "-").Insert(5,"-").Insert(8, "-").Insert(11, "-").Insert(14, "-")
Log("Hardware Address:" & sb.ToString)
Output Hardware Address:2C-D0-5A-54-96-47
Option using jShell with ipconfig / ifconfig
The result, stdout, can be parsed.
`Sub Process_Globals
Private shl As Shell
...
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
...
AppInit
End Sub`
`Sub AppInit
Private shlCommand As String
Dim args As List
Dim os As String = GetSystemProperty("os.name", "").ToLowerCase
args.Initialize
' Windows 8
If os.Contains("win") Then
shlCommand = "ipconfig"
' add arguments
' Mac
Else If os.Contains("mac") Then
shlCommand = "ifconfig"
' add arguments
' Linux
Else
shlCommand = "ifconfig"
' add arguments
End If
Try
shl.Initialize("shl", shlCommand, args)
shl.WorkingDirectory = File.DirApp
shl.Run(-1)
Catch
Log(LastException.Message)
End Try
End Sub`
`Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
If Success And ExitCode = 0 Then
Log("Shell Command Success")
Log(StdOut)
Else
Log("Shell Command Error: " & StdErr)
End If
ExitApplication
End Sub`

Changed: , Category: Network, File: T6C224M1654.htm, ID: 1654