### Get your local IP Address

Various options to obtain the local IP address
Option using the ServerSocket class from the jNetwork Library.
`Sub Process_Globals
Private jIP As ServerSocket
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
Dim localip As String = jIP.GetMyIP
Log("The Local IP Address for this device is:" & localip)
End Sub`
OR
Dim localip As ServerSocket
localip.Initialize(1, "")
Log($"GetMyIP: ${local.GetMyIP}"$)
Option using Inline Java
`Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private joInlineJava As JavaObject = Me
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
Log(joInlineJava.RunMethod("myInetAddress", Null))
MainForm.Close
End Sub`
If Java
import java.net.InetAddress;
public static String myInetAddress() throws Exception
{
return InetAddress.getLocalHost().toString();
}
End If
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: 2018-03-28 10:48, Category: Network, File: T6C224M1658.htm, ID: 1658