VisualLANSA Windows client IP Address
VisualLANSA Windows client IP Address
I would need to get IPV4 IP address of PC, where VL windows client runs. Or list of active addresses (one station can have more IP addresses, i.e in case of using VPN). Could you advice me a simple way, how to get it in VL application?
Re: VisualLANSA Windows client IP Address
In our VL web applications, we use the system variable *WEBIPADDR to log the requesting client's IP address in our server modules.
Arlyn Dale
Servias LLC
Servias LLC
Re: VisualLANSA Windows client IP Address
In VL-WEB it is not problem, and Web client has only one address. But Windows client can have more IP Addresses and *WEBIPADDR does not work in native Windows (not web) client.
Re: VisualLANSA Windows client IP Address
I found this old example from 2011 via the Forum that was in place at that time. I haven't tried it in LANSA V15 or whether recent versions of Windows have locked down the command interface, or whether the command output is formatted differently in 2024, Note that when using VPN or using multiple network cards you will have multiple IP addresses
*method writes the result of ipconfig to a text file in %temp% and then reads it to get the address.
*oSystem is a class in the Qindows Script defined as an Active X component.
Define_Com Class(#TKX_WSCR1.iWshEnvironment) Name(#oSystem) Reference(*DYNAMIC)
*ONetwork is a different co class.
Define_Com Class(#TKX_WSCR1.WshNetwork) Name(#oNetwork) Reference(*DYNAMIC)
Mthroutine Name(mComputer) Help('Load Computer Name and IP Address Properties')
Define_Com Class(#prim_alph) Name(#lIp)
Define Field(#w_ip) Type(*char) Length(256)
Def_List Name(#l_ip) Fields(#w_ip) Type(*working) Entrys(*max)
#sysupnm := #oUtility.oNetwork.ComputerName
#sysupid := *null
#lIp := *temp_dir + *component + 'ip.txt'
Clr_List Named(#l_ip)
If (#oUtility.oSystem<OS> = '')
#oUtility.mRun( ('winipcfg /batch ' + #lIp) )
Else
#oUtility.mRun( ('%comspec% /c ipconfig > ' + #lIp) 0 )
Endif
Use Builtin(transform_file) With_Args(#l_ip #lIp T) To_Get(#r_status)
Selectlist Named(#l_ip)
If (#w_ip.contains( 'Address' ))
#int2 := #w_ip.PositionOf( ':' )
#sysupip := #w_ip.substring( (#int2 + 2) 15 )
Endif
Endselect
#sysuprt := *partition
Use Builtin(ov_file_service) With_Args(remove_file #lIp force) To_Get(#io$sts)
Endroutine
*method writes the result of ipconfig to a text file in %temp% and then reads it to get the address.
*oSystem is a class in the Qindows Script defined as an Active X component.
Define_Com Class(#TKX_WSCR1.iWshEnvironment) Name(#oSystem) Reference(*DYNAMIC)
*ONetwork is a different co class.
Define_Com Class(#TKX_WSCR1.WshNetwork) Name(#oNetwork) Reference(*DYNAMIC)
Mthroutine Name(mComputer) Help('Load Computer Name and IP Address Properties')
Define_Com Class(#prim_alph) Name(#lIp)
Define Field(#w_ip) Type(*char) Length(256)
Def_List Name(#l_ip) Fields(#w_ip) Type(*working) Entrys(*max)
#sysupnm := #oUtility.oNetwork.ComputerName
#sysupid := *null
#lIp := *temp_dir + *component + 'ip.txt'
Clr_List Named(#l_ip)
If (#oUtility.oSystem<OS> = '')
#oUtility.mRun( ('winipcfg /batch ' + #lIp) )
Else
#oUtility.mRun( ('%comspec% /c ipconfig > ' + #lIp) 0 )
Endif
Use Builtin(transform_file) With_Args(#l_ip #lIp T) To_Get(#r_status)
Selectlist Named(#l_ip)
If (#w_ip.contains( 'Address' ))
#int2 := #w_ip.PositionOf( ':' )
#sysupip := #w_ip.substring( (#int2 + 2) 15 )
Endif
Endselect
#sysuprt := *partition
Use Builtin(ov_file_service) With_Args(remove_file #lIp force) To_Get(#io$sts)
Endroutine
-
Theo de Bruin
- Posts: 29
- Joined: Wed Feb 10, 2016 8:41 pm
Re: VisualLANSA Windows client IP Address
Hi, here some more tips to this subject:
1) This way to get the users' temp directory may work well in all cases :
Define_Com Class(#STD_STRNG) Name(#USER_APPDATA)
Define_Com Class(#STD_STRNG) Name(#USER_PROFILE)
Define_Com Class(#STD_STRNG) Name(#USER_TMP_PATH)
* determine the user profile, user appdata and user temp path
#STD_QORD := 'Volatile Environment'
#STD_INSTR := 'USERPROFILE'
Use Builtin(get_registry_value) With_Args(HKEY_CURRENT_USER #STD_QORD #STD_INSTR) To_Get(#USER_PROFILE #RETCOD2)
#STD_INSTR := 'LOCALAPPDATA'
Use Builtin(get_registry_value) With_Args(HKEY_CURRENT_USER #STD_QORD #STD_INSTR) To_Get(#USER_APPDATA #RETCOD2)
#USER_TMP_PATH := #USER_APPDATA + '\temp\'
2) This (Powershell) script can deliver the IP address(es) :
(get-ciminstance -Query "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE DNSHostName = '$([System.Environment]::MachineName)'")[0].IPAddress[0]
or this to store the output to a file in the users temp directory :
(get-ciminstance -Query "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE DNSHostName = '$([System.Environment]::MachineName)'")[0].IPAddress[0] | Out-String -Width 256 | out-file -encoding utf8 "$env:temp\IPAddress,txt"
store this as a Powershell script , e.g. getIPaddr.ps1
and embed it in VL with :
* Get IP Address
Def_List Name(#WLIST) Fields(#STD_STRNG) Counter(#STD_COUNT) Type(*WORKING) Entrys(*MAX)
#STD_QSEL := '/f /c Powershell < getIPaddr.ps1'
Use Builtin(SYSTEM_COMMAND) With_Args(B 'CMD /Admin' #STD_QSEL) To_Get(#std_num)
#STD_QSEL := #USER_TMP_PATH + '/IPAddress.txt'
Use Builtin(TRANSFORM_FILE) With_Args(#WLIST #STD_QSEL TU B Y) To_Get(#RETCOD)
Selectlist Named(#WLIST)
#IP_ADDRESS := #STD_STRNG
Leave
Endselect
(see also this article: https://adamtheautomator.com/powershell-get-ip-address/ )
3) You may set the current temp path location for LANSA execution yourself within LANSA
by using the TPTH= parameter , e.g. in X_LANSA,PRO to point to any path you choose!!
1) This way to get the users' temp directory may work well in all cases :
Define_Com Class(#STD_STRNG) Name(#USER_APPDATA)
Define_Com Class(#STD_STRNG) Name(#USER_PROFILE)
Define_Com Class(#STD_STRNG) Name(#USER_TMP_PATH)
* determine the user profile, user appdata and user temp path
#STD_QORD := 'Volatile Environment'
#STD_INSTR := 'USERPROFILE'
Use Builtin(get_registry_value) With_Args(HKEY_CURRENT_USER #STD_QORD #STD_INSTR) To_Get(#USER_PROFILE #RETCOD2)
#STD_INSTR := 'LOCALAPPDATA'
Use Builtin(get_registry_value) With_Args(HKEY_CURRENT_USER #STD_QORD #STD_INSTR) To_Get(#USER_APPDATA #RETCOD2)
#USER_TMP_PATH := #USER_APPDATA + '\temp\'
2) This (Powershell) script can deliver the IP address(es) :
(get-ciminstance -Query "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE DNSHostName = '$([System.Environment]::MachineName)'")[0].IPAddress[0]
or this to store the output to a file in the users temp directory :
(get-ciminstance -Query "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE DNSHostName = '$([System.Environment]::MachineName)'")[0].IPAddress[0] | Out-String -Width 256 | out-file -encoding utf8 "$env:temp\IPAddress,txt"
store this as a Powershell script , e.g. getIPaddr.ps1
and embed it in VL with :
* Get IP Address
Def_List Name(#WLIST) Fields(#STD_STRNG) Counter(#STD_COUNT) Type(*WORKING) Entrys(*MAX)
#STD_QSEL := '/f /c Powershell < getIPaddr.ps1'
Use Builtin(SYSTEM_COMMAND) With_Args(B 'CMD /Admin' #STD_QSEL) To_Get(#std_num)
#STD_QSEL := #USER_TMP_PATH + '/IPAddress.txt'
Use Builtin(TRANSFORM_FILE) With_Args(#WLIST #STD_QSEL TU B Y) To_Get(#RETCOD)
Selectlist Named(#WLIST)
#IP_ADDRESS := #STD_STRNG
Leave
Endselect
(see also this article: https://adamtheautomator.com/powershell-get-ip-address/ )
3) You may set the current temp path location for LANSA execution yourself within LANSA
by using the TPTH= parameter , e.g. in X_LANSA,PRO to point to any path you choose!!
Re: VisualLANSA Windows client IP Address
With this great support we got working it finally. We modified the powershell script to be abble get all IPV4 addresses, if the workstation have more (my NTB about six due to VPNs etc). We also modified some other details to be safe. The example form code is bellow, if you need the logic, all is included in the method. You can replace only the visual list by any other logic.
The final script X_getIPaddr.ps1 to be placed into PARTITION EXECUTE directory (i.e. \..X_LANSA\X_DEM\EXECUTE\ )
# Get all IP adresses into file
Get-CimInstance -Query "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True" |
ForEach-Object {
# Only IPv4
$_.IPAddress | Where-Object { $_ -match "^\d{1,3}(\.\d{1,3}){3}$" }
} |
Out-String -Width 256 |
Out-File -Encoding utf8 "$env:LOCALAPPDATA\TEMP\IPAddress.txt"
Form logic
BEGIN_COM ROLE(*EXTENDS #PRIM_FORM) CLIENTWIDTH(344) CLIENTHEIGHT(259) WIDTH(360) HEIGHT(298) LEFT(252)
DEFINE_COM CLASS(#PRIM_GRID) NAME(#IPADD_LST_visual) CAPTIONNOBLANKLINES(True) COLUMNSCROLL(False) COMPONENTVERSION(1) DISPLAYPOSITION(2) LEFT(48) PARENT(#COM_OWNER) SHOWSELECTION(True) SHOWSELECTIONHILIGHT(False) SHOWSORTARROW(True) TABPOSITION(2) TOP(15) WIDTH(270) HEIGHT(193)
DEFINE_COM CLASS(#PRIM_GDCL) NAME(#GridColumn1) DISPLAYPOSITION(1) PARENT(#IPADD_LST_visual) SOURCE(#STD_STRNG) WIDTHTYPE(Remainder) CAPTIONTYPE(Caption) CAPTION('IP Address')
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#Button1) CAPTION('Refresh') DISPLAYPOSITION(3) LEFT(296) PARENT(#COM_OWNER) TABPOSITION(3) TOP(392)
DEFINE_COM CLASS(#PRIM_STBR) NAME(#StatusBar1) DISPLAYPOSITION(1) HEIGHT(24) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(1) TABSTOP(False) TOP(235) WIDTH(344)
* Get IP Address
MTHROUTINE NAME(GET_IP)
DEFINE_COM CLASS(#STD_STRNG) NAME(#USER_APPDATA)
DEFINE FIELD(#Y_TMPFILE) REFFLD(#STD_QSEL)
DEF_LIST NAME(#WLIST) FIELDS(#STD_STRNG) TYPE(*WORKING) ENTRYS(*MAX)
*
* determine the user appdata and user temp path
#STD_QORD := 'Volatile Environment'
#STD_INSTR := 'LOCALAPPDATA'
USE BUILTIN(get_registry_value) WITH_ARGS(HKEY_CURRENT_USER #STD_QORD #STD_INSTR) TO_GET(#USER_APPDATA #IO$STS)
#STD_QSEL := 'CMD /Admin /f /c Powershell < ' + *PART_DIR_EXECUTE + 'X_getIPaddr.ps1'
USE BUILTIN(SYSTEM_COMMAND) WITH_ARGS(B #STD_QSEL) TO_GET(#std_num)
#Y_TMPFILE := #USER_APPDATA + '\temp\' + 'IPAddress.txt'
USE BUILTIN(TRANSFORM_FILE) WITH_ARGS(#WLIST #Y_TMPFILE TU B Y) TO_GET(#IO$STS)
SELECTLIST NAMED(#WLIST)
IF (#STD_STRNG *NE *BLANK)
ADD_ENTRY TO_LIST(#IPADD_LST_visual)
ENDIF
ENDSELECT
USE BUILTIN(ov_file_service) WITH_ARGS(remove_file #Y_TMPFILE force) TO_GET(#io$sts)
ENDROUTINE
EVTROUTINE HANDLING(#COM_OWNER.Initialize #Button1.Click)
CLR_LIST NAMED(#IPADD_LST_visual)
#COM_OWNER.GET_IP
ENDROUTINE
END_COM
The final script X_getIPaddr.ps1 to be placed into PARTITION EXECUTE directory (i.e. \..X_LANSA\X_DEM\EXECUTE\ )
# Get all IP adresses into file
Get-CimInstance -Query "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True" |
ForEach-Object {
# Only IPv4
$_.IPAddress | Where-Object { $_ -match "^\d{1,3}(\.\d{1,3}){3}$" }
} |
Out-String -Width 256 |
Out-File -Encoding utf8 "$env:LOCALAPPDATA\TEMP\IPAddress.txt"
Form logic
BEGIN_COM ROLE(*EXTENDS #PRIM_FORM) CLIENTWIDTH(344) CLIENTHEIGHT(259) WIDTH(360) HEIGHT(298) LEFT(252)
DEFINE_COM CLASS(#PRIM_GRID) NAME(#IPADD_LST_visual) CAPTIONNOBLANKLINES(True) COLUMNSCROLL(False) COMPONENTVERSION(1) DISPLAYPOSITION(2) LEFT(48) PARENT(#COM_OWNER) SHOWSELECTION(True) SHOWSELECTIONHILIGHT(False) SHOWSORTARROW(True) TABPOSITION(2) TOP(15) WIDTH(270) HEIGHT(193)
DEFINE_COM CLASS(#PRIM_GDCL) NAME(#GridColumn1) DISPLAYPOSITION(1) PARENT(#IPADD_LST_visual) SOURCE(#STD_STRNG) WIDTHTYPE(Remainder) CAPTIONTYPE(Caption) CAPTION('IP Address')
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#Button1) CAPTION('Refresh') DISPLAYPOSITION(3) LEFT(296) PARENT(#COM_OWNER) TABPOSITION(3) TOP(392)
DEFINE_COM CLASS(#PRIM_STBR) NAME(#StatusBar1) DISPLAYPOSITION(1) HEIGHT(24) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(1) TABSTOP(False) TOP(235) WIDTH(344)
* Get IP Address
MTHROUTINE NAME(GET_IP)
DEFINE_COM CLASS(#STD_STRNG) NAME(#USER_APPDATA)
DEFINE FIELD(#Y_TMPFILE) REFFLD(#STD_QSEL)
DEF_LIST NAME(#WLIST) FIELDS(#STD_STRNG) TYPE(*WORKING) ENTRYS(*MAX)
*
* determine the user appdata and user temp path
#STD_QORD := 'Volatile Environment'
#STD_INSTR := 'LOCALAPPDATA'
USE BUILTIN(get_registry_value) WITH_ARGS(HKEY_CURRENT_USER #STD_QORD #STD_INSTR) TO_GET(#USER_APPDATA #IO$STS)
#STD_QSEL := 'CMD /Admin /f /c Powershell < ' + *PART_DIR_EXECUTE + 'X_getIPaddr.ps1'
USE BUILTIN(SYSTEM_COMMAND) WITH_ARGS(B #STD_QSEL) TO_GET(#std_num)
#Y_TMPFILE := #USER_APPDATA + '\temp\' + 'IPAddress.txt'
USE BUILTIN(TRANSFORM_FILE) WITH_ARGS(#WLIST #Y_TMPFILE TU B Y) TO_GET(#IO$STS)
SELECTLIST NAMED(#WLIST)
IF (#STD_STRNG *NE *BLANK)
ADD_ENTRY TO_LIST(#IPADD_LST_visual)
ENDIF
ENDSELECT
USE BUILTIN(ov_file_service) WITH_ARGS(remove_file #Y_TMPFILE force) TO_GET(#io$sts)
ENDROUTINE
EVTROUTINE HANDLING(#COM_OWNER.Initialize #Button1.Click)
CLR_LIST NAMED(#IPADD_LST_visual)
#COM_OWNER.GET_IP
ENDROUTINE
END_COM