Obtaining your NA HMI IP address at runtime
Use VB.Net to read the HMI IP address
Introduction
Sometimes it is required to read the HMI IP address in a project. As there is no system variable which contains this information, a VB script to read the port IP addresses is used. This is a very simple VB script that uses the System.Net.DNS include. item0 to item3 are string display objects on the HMI but can be changed to suit the use case.
Link to download the example project
Sub getNAip
exc0 = "" exc1 = "" exc2 = "" exc3 = "" Dim strHostName = System.Net.Dns.GetHostName() Dim hostInfo = System.Net.Dns.GetHostByName(strHostName) Try item0 = hostInfo.AddressList(0).ToString() Catch ex As Exception exc0 = ex.Message item0 = "" End Try Try item1 = hostInfo.AddressList(1).ToString() Catch ex As Exception exc1 = ex.Message item1 = "" End Try Try item2 = hostInfo.AddressList(2).ToString() Catch ex As Exception exc2 = ex.Message item2 = "" End Try Try item3 = hostInfo.AddressList(3).ToString() Catch ex As Exception exc3 = ex.Message item3 = "" End Try End Sub