hm2k Posted May 22, 2009 Share Posted May 22, 2009 Sometimes @IPAddress1 @IPAddress2 @IPAddress3 @IPAddress4 aren't enough. I created this function to get a local IP address of a network interface. You can specify a variable that will offset the result to another interface. Func _GetLocalIP($offset=1) Local $ip, $k, $i=0, $r=1 $k='HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces' While($r) $i=$i+1 $r=RegEnumKey($k,$i) If (@error <> 0) Then $r=0 EndIf $ip=RegRead($k & '\' & $r,'IPAddress') If (($ip) And ($ip = '0.0.0.0')) Then $ip=RegRead($k & '\' & $r,'DhcpIPAddress') EndIf If (($ip) And Not ($ip = '0.0.0.0')) Then If ($i == $offset) Then Return $ip EndIf EndIf WEnd SetError(1) Return -1 EndFunc ;Testing $ip=_GetLocalIP() InputBox('Testing', 'Your Local IP Address...', $ip) Link to comment Share on other sites More sharing options...
martin Posted May 22, 2009 Share Posted May 22, 2009 Sometimes @IPAddress1 @IPAddress2 @IPAddress3 @IPAddress4 aren't enough. I created this function to get a local IP address of a network interface. You can specify a variable that will offset the result to another interface. Func _GetLocalIP($offset=1) Local $ip, $k, $i=0, $r=1 $k='HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces' While($r) $i=$i+1 $r=RegEnumKey($k,$i) If (@error <> 0) Then $r=0 EndIf $ip=RegRead($k & '\' & $r,'IPAddress') If (($ip) And ($ip = '0.0.0.0')) Then $ip=RegRead($k & '\' & $r,'DhcpIPAddress') EndIf If (($ip) And Not ($ip = '0.0.0.0')) Then If ($i == $offset) Then Return $ip EndIf EndIf WEnd SetError(1) Return -1 EndFunc ;Testing $ip=_GetLocalIP() InputBox('Testing', 'Your Local IP Address...', $ip)How do you know what offset to use? I need to use 2 to get my IP, or at least I do at the moment. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
hm2k Posted May 26, 2009 Author Share Posted May 26, 2009 What does 1 return? 1 should return the first network interface IP address instance, 2 should return the second. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now