Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/05/2018 in all areas

  1. 3 points
  2. there are soooo many ways to do this. Understanding why mikell is right is a greater goal than just using his correct solutions. #include<array.au3> $str = "What I need to have happen is to then to go back ... and extract the number 75,689 that is listed in each string." msgbox(0, '' , StringStripWS(_ArrayToString(stringsplit($str , "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ." , 2), ""), 3))
    3 points
  3. How? Did you read / try any of these solutions?
    1 point
  4. Juvigy

    Autoit Crushes

    Compiling it to EXE and executing that EXE in a loop from SCITE works.
    1 point
  5. jdelaney

    Autoit Crushes

    Put in an error handler to get the actual reason for the crash. Forgot the function name, something like _ieerrorhandlerregister.
    1 point
  6. Juvigy

    Autoit Crushes

    Sorry about that (crush) - seems some stupid auto corrector is changing some words - i switched the damn thing off. So i put the debug option: AutoItSetOption("TrayIconDebug", 1) And run the code again. It 'crushed' after SaveChanges() function on the Sleep command ! Func SaveChanges() $oFrames = _IEFrameGetCollection ($oIE) $iNumFrames = @extended For $i = 0 to ($iNumFrames - 1) $oFrame = _IEFrameGetCollection ($oIE, $i) ;~ ConsoleWrite($oFrame.Name & "----1----" & _IEPropertyGet($oFrame,'title') & @CRLF) $oButs = _IETagNameGetCollection($oFrame, "button") For $oBut in $oButs IF $oBut.innerhtml = "Save" Then ;~ ConsoleWrite("Test:"&$oBut.id&@CRLF) _IEAction($oBut,"click") ;~ Return 1 EndIf Next Next EndFunc
    1 point
  7. Earthshine

    Autoit Crushes

    LOL. I kind of liked AHK back in the day
    1 point
  8. Zedna

    Autoit Crushes

    I think he is not familiar with English and it could be crash.
    1 point
  9. Zedna

    Autoit Crushes

    Place more debug ConsoleWrite() into your script to see which exact line/command fails ...
    1 point
  10. j0kky

    Winsock UDF

    Hi guys, some time ago I tried to deal with client\server application using native winsock functions, but I encountered some difficult because their limitations, so I decided to write a new UDF based on winsock library. Some functions are simply wrappers of native function, but some other are completely renewed and there are a lot of improvements. Check it out! Each function has a detailed description and I attached 5 simple example script ; #INDEX# ======================================================================================================================= ; Title .........: Winsock ; AutoIt Version : 3.3.14.2 ; Language ......: English ; Description ...: Functions that assist with Winsock library management. ; Author(s) .....: j0kky ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== Global Const $TCP_DATA_EOT = 2 ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _TCPStartup ; _TCPListen ; _TCPAccept ; _TCPRecv ; _TCPConnect ; _TCPSend ; _TCPNameToIP ; _TCPCloseSocket ; _TCPShutdown ; _GetIps ; _UDPStartup ; _UDPBind ; _UDPSendTo ; _UDPRecvFrom ; _UDPCloseSocket ; _UDPShutdown ; =============================================================================================================================== ; #WRAPPER# ===================================================================================================================== Func _TCPStartup() $iResult = TCPStartup() Return SetError(@error, 0, $iResult) EndFunc ;==>_TCPStartup ; #WRAPPER# ===================================================================================================================== Func _TCPListen($iIPAddr, $iPort, $iMaxPendingConnection = 0) If Not $iMaxPendingConnection Then $iResult = TCPListen($iIPAddr, $iPort) Else $iResult = TCPListen($iIPAddr, $iPort, $iMaxPendingConnection) EndIf Return SetError(@error, 0, $iResult) EndFunc ;==>_TCPListen ; #FUNCTION# ==================================================================================================================== ; Name...........: _TCPAccept ; Description ...: Permits an incoming connection attempt on a socket. ; Syntax.........: _TCPAccept($iMainsocket) ; Parameters ....: $iMainsocket - The main socket identifier (SocketID) as returned by _TCPListen function. ; Return values .: On success it returns an array: ; |[0] - The connected socket identifier. ; |[1] - The external address of the client ; |[2] - The external port which the client are communicating on ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter (not used in this function) ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Links .........: accept: https://msdn.microsoft.com/en-us/library/windows/desktop/ms737526(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _TCPAccept($iMainsocket) $iMainsocket = Number($iMainsocket) If $iMainsocket < 0 Then Return SetError(-4, 0, -1) ; invalid parameter Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0, $hSock = 0 Local $tagSockAddr = "short sin_family; ushort sin_port; " & _ "STRUCT; ulong S_addr; ENDSTRUCT; " & _ ;sin_addr "char sin_zero[8]" If Not $bError Then $aRet = DllCall($hWs2, "int", "ioctlsocket", "uint", $iMainsocket, "long", 0x8004667e, "ulong*", 1) ;FIONBIO If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf EndIf If Not $bError Then $tSockAddr = DllStructCreate($tagSockAddr) $aRet = DllCall($hWs2, "uint", "accept", "uint", $iMainsocket, "ptr", DllStructGetPtr($tSockAddr), "int*", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf ($aRet[0] = 4294967295) Or ($aRet[0] = -1) Then ;INVALID_SOCKET $bError = 1 $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $bError = -1 ElseIf ($aRet[0] = 0) Or ($aRet[0] = 10035) Then ;WSAEWOULDBLOCK $nCode = -10 ;internal function value, it means no error EndIf Else $hSock = $aRet[0] $aRet = DllCall($hWs2, "ptr", "inet_ntoa", "ulong", DllStructGetData($tSockAddr, "S_addr")) If @error Then $bError = -1 ElseIf $aRet[0] = Null Then $bError = 1 Else $sIPAddr = DllStructGetData(DllStructCreate("char[15]", $aRet[0]), 1) $aRet = DllCall($hWs2, "ushort", "ntohs", "ushort", DllStructGetData($tSockAddr, "sin_port")) If @error Then $bError = -1 Else $nPort = $aRet[0] Local $aResult[3] = [$hSock, $sIPAddr, $nPort] EndIf EndIf EndIf EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure If $hSock Then TCPCloseSocket($hSock) ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf If $nCode = -10 Then $nCode = 0 $nReturn = -1 If $hSock Then TCPCloseSocket($hSock) Else $nReturn = $aResult EndIf DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_TCPAccept ; #FUNCTION# ==================================================================================================================== ; Name...........: _TCPRecv ; Description ...: Receives data from a connected socket. ; Syntax.........: _TCPRecv($iMainsocket, $iMaxLen, $iFlag = 0) ; Parameters ....: $iMainsocket - The array as returned by _TCPAccept ; or the connected socket identifier (SocketID) as returned by _TCPConnect. ; $iMaxLen - max # of characters to receive (usually 2048). ; $iFlag - values can be added together ; |$TCP_DATA_DEFAULT (0) - Text data. [Default] ; |$TCP_DATA_BINARY (1) - Binary data. ; |$TCP_DATA_EOT (2) - Returns data received and ; set @error to -6 when it reaches the End of Text ASCII character (Chr(3)) ; Return values .: On success it returns the binary/string sent by the connected socket. ; On failure it returns "" and sets the @error or @extended flag to non-zero: ; @error values: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; @extended values: ; |1 - connection closed ; |2 - End of Text reached ; Author ........: j0kky ; Modified ......: 1.0.0 ; Remarks .......: If Unicode strings need to be transmitted they must be encoded/decoded with StringToBinary()/BinaryToString(). ; $iFlag = 2 must be set in couple with _TCPSend ; You must check for both @error and @extended, @extended could be set with @error set to zero ; Links .........: recv: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740121(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _TCPRecv($iMainsocket, $iMaxLen, $iFlag = 0) If IsArray($iMainsocket) And (UBound($iMainsocket, 0) = 1) And (UBound($iMainsocket) > 0) Then $iMainsocket = $iMainsocket[0] If $iFlag = Default Then $iFlag = 0 $iMainsocket = Number($iMainsocket) $iMaxLen = Number($iMaxLen) $iFlag = Number($iFlag) If $iMainsocket < 0 Or _ $iMaxLen < 1 Or _ Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(-4, 0, -1) ; invalid parameter Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0, $nExtended = 0 If Not $bError Then $aRet = DllCall($hWs2, "int", "ioctlsocket", "uint", $iMainsocket, "long", 0x8004667e, "ulong*", 1) ;FIONBIO If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf EndIf Local $tBuf If $iFlag Then $tBuf = DllStructCreate("byte[" & $iMaxLen & "]") Else $tBuf = DllStructCreate("char[" & $iMaxLen & "]") EndIf $aRet = DllCall($hWs2, "int", "recv", "uint", $iMainsocket, "ptr", DllStructGetPtr($tBuf), "int", $iMaxLen, "int", 0) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Then ;SOCKET_ERROR $bError = 1 $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $bError = -1 ElseIf $aRet[0] = 0 Or $aRet[0] = 10035 Then ;WSAEWOULDBLOCK $nCode = -10 ;internal function value, it means no error EndIf ElseIf $aRet[0] = 0 Then $bError = 1 $nCode = -10 $nExtended = 1 ;connection closed Else Local $sResult = DllStructGetData($tBuf, 1) ;data If BitAND($iFlag, 2) = 2 Then ;EOT If StringRight($sResult, 1) = Chr(3) Then $sResult = StringTrimRight($sResult, 1) $nExtended = 2 ;End of Text reached EndIf EndIf EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = "" ;failure ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf If $nCode = -10 Then $nCode = 0 $nReturn = "" Else $nReturn = $sResult EndIf DllClose($hWs2) Return SetError($nCode, $nExtended, $nReturn) EndFunc ;==>_TCPRecv ; #FUNCTION# ==================================================================================================================== ; Name...........: _TCPConnect ; Description ...: Create a socket connected to an existing server. ; Syntax.........: _TCPConnect($sIPAddr, $iDestPort, $sSourceAddr = "", $iSourcePort = 0, $iTimeOut = 0) ; Parameters ....: $sIPAddr - Destination IP. ; |Internet Protocol dotted address(IpV4) as "192.162.1.1". ; $iDestPort - Destination port. ; |1 : 65534 - port on which the created socket will be connected. ; $sSourceAddr - Source IP ; |Internet Protocol dotted address(IpV4) as "192.162.1.1". [Default = ""] ; $iSourcePort - Source port. ; |1 : 65534 - port on which the created socket will be bind (on the local PC). [Default = 0] ; $iTimeOut - The maximum time in milliseconds for _TCPConnect to wait for connection. ; |Any value > 0 [Default = 0 and it will be equal to Opt("TCPTimeout")]. ; Return values .: On success it returns the main socket identifier. ; |Any value > 0 ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter ; |-5 - not connected ; |-6 - timed out ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Remarks .......: This function is used by a client to communicate with the server and it allows to choose a source IP, ; a source port and to set a timeout for the connection. ; Links .........: bind: https://msdn.microsoft.com/en-us/library/windows/desktop/ms737550(v=vs.85).aspx ; connect: https://msdn.microsoft.com/en-us/library/windows/desktop/ms737625(v=vs.85).aspx ; select: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740141(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _TCPConnect($sIPAddr, $iDestPort, $sSourceAddr = "", $iSourcePort = 0, $iTimeOut = 0) If $sSourceAddr = Default Then $sSourceAddr = "" If $iSourcePort = Default Then $iSourcePort = 0 If $iTimeOut = Default Then $iTimeOut = 0 $sIPAddr = String($sIPAddr) $iDestPort = Number($iDestPort) $sSourceAddr = String($sSourceAddr) $iSourcePort = Number($iSourcePort) $iTimeOut = Number($iTimeOut) If Not ($iDestPort > 0 And $iDestPort < 65535) Or _ Not ($iSourcePort >= 0 And $iSourcePort < 65535) Or _ Not ($iTimeOut >= 0) Then Return SetError(-4, 0, -1) ; invalid parameter StringRegExp($sIPAddr, "((?:\d{1,3}\.){3}\d{1,3})", 3) ;$STR_REGEXPARRAYGLOBALMATCH If @error Then Return SetError(-4, 0, -1) If $sSourceAddr <> "" Then StringRegExp($sSourceAddr, "((?:\d{1,3}\.){3}\d{1,3})", 3) ;$STR_REGEXPARRAYGLOBALMATCH If @error Then Return SetError(-4, 0, -1) EndIf Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0 Local $tagSockAddr = "short sin_family; ushort sin_port; " & _ "STRUCT; ulong S_addr; ENDSTRUCT; " & _ ;sin_addr "char sin_zero[8]" Local $hSock = DllCall($hWs2, "uint", "socket", "int", 2, "int", 1, "int", 6); AF_INET, SOCK_STREAM, IPPROTO_TCP If @error Then $bError = -1 ElseIf ($hSock[0] = 4294967295) Or ($hSock[0] = -1) Then ;INVALID_SOCKET $bError = 1 Else $hSock = $hSock[0] EndIf If Not $bError Then $aRet = DllCall($hWs2, "ulong", "inet_addr", "str", $sIPAddr) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Or ($aRet[0] = 0) Then ;INADDR_NONE or INADDR_ANY $bError = 1 Else $sIPAddr = $aRet[0] EndIf EndIf If Not $bError Then $aRet = DllCall($hWs2, "ushort", "htons", "ushort", $iDestPort) If @error Then $bError = -1 Else $iDestPort = $aRet[0] EndIf EndIf If (Not $bError) And ($sSourceAddr <> "") Then $aRet = DllCall($hWs2, "ulong", "inet_addr", "str", $sSourceAddr) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Or ($aRet[0] = 0) Then ;INADDR_NONE or INADDR_ANY $bError = 1 Else $sSourceAddr = $aRet[0] EndIf EndIf If (Not $bError) And $iSourcePort Then $aRet = DllCall($hWs2, "ushort", "htons", "ushort", $iSourcePort) If @error Then $bError = -1 Else $iSourcePort = $aRet[0] EndIf EndIf If (Not $bError) And ($sSourceAddr Or $iSourcePort) Then $tSockAddr = DllStructCreate($tagSockAddr) DllStructSetData($tSockAddr, "sin_family", 2) ;AF_INET If $iSourcePort Then DllStructSetData($tSockAddr, "sin_port", $iSourcePort) Else DllStructSetData($tSockAddr, "sin_port", 0) EndIf If $sSourceAddr Then DllStructSetData($tSockAddr, "S_addr", $sSourceAddr) Else DllStructSetData($tSockAddr, "S_addr", 0x00000000) ;INADDR_ANY EndIf $aRet = DllCall($hWs2, "int", "bind", "uint", $hSock, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf $tSockAddr = 0 EndIf If Not $bError Then $aRet = DllCall($hWs2, "int", "ioctlsocket", "uint", $hSock, "long", 0x8004667e, "ulong*", 1) ;FIONBIO If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf EndIf If Not $bError Then $tSockAddr = DllStructCreate($tagSockAddr) DllStructSetData($tSockAddr, "sin_family", 2) ;AF_INET DllStructSetData($tSockAddr, "sin_port", $iDestPort) DllStructSetData($tSockAddr, "S_addr", $sIPAddr) $aRet = DllCall($hWs2, "int", "connect", "uint", $hSock, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR -> functional with connect() on non-blocking sockets $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $bError = -1 ElseIf ($aRet[0] <> 0) And ($aRet[0] <> 10035) Then ;WSAEWOULDBLOCK $bError = 1 EndIf EndIf $tSockAddr = 0 EndIf If Not $bError Then If $iTimeOut = 0 Then $iTimeOut = Opt("TCPTimeout") If $iTimeOut < 1 Then $iTimeOut = 100 Local $tagFd_set = "uint fd_count; uint fd_array[64]" Local $tFd_set_writefds = DllStructCreate($tagFd_set) DllStructSetData($tFd_set_writefds, "fd_count", 1) DllStructSetData($tFd_set_writefds, "fd_array", $hSock, 1) Local $tFd_set_exceptfds = DllStructCreate($tagFd_set) DllStructSetData($tFd_set_exceptfds, "fd_count", 1) DllStructSetData($tFd_set_exceptfds, "fd_array", $hSock, 1) Local $tTimeval = DllStructCreate("long tv_sec; long tv_usec") DllStructSetData($tTimeval, "tv_sec", Floor($iTimeOut / 1000)) DllStructSetData($tTimeval, "tv_usec", Round(Mod($iTimeOut, 1000) * 1000)) $aRet = DllCall($hWs2, "int", "select", _ "int", $hSock, "ptr", 0, "ptr", DllStructGetPtr($tFd_set_writefds), "ptr", DllStructGetPtr($tFd_set_exceptfds), "ptr", DllStructGetPtr($tTimeval)) If @error Then $bError = -1 ElseIf $aRet[0] = 0 Then ;time expired $bError = 1 $nCode = -6 ;timed out, similar to WSAETIMEDOUT ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Then ;SOCKET_ERROR $bError = 1 Else If Not (DllStructGetData($tFd_set_writefds, "fd_count") = 1) Then $bError = 1 If DllStructGetData($tFd_set_exceptfds, "fd_count") = 1 Then $tBuf = DllStructCreate("int") $aRet = DllCall("Ws2_32.dll", "int", "getsockopt", _ "uint", $hSock, "int", 0xffff, "int", 0x1007, "ptr", DllStructGetPtr($tBuf), "int*", DllStructGetSize($tBuf)) ;SO_ERROR If @error Then $bError = -1 ElseIf $aRet[0] = 0 Then $nCode = DllStructGetData($tBuf, 1) EndIf Else $nCode = -5 ;NOT_CONNECTED EndIf EndIf EndIf EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure If $hSock Then TCPCloseSocket($hSock) ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf $nReturn = -1 If $hSock Then TCPCloseSocket($hSock) Else $nReturn = $hSock EndIf DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_TCPConnect ; #MODIFIED WRAPPER# ============================================================================================================ ; Name...........: _TCPSend ; Description ...: Wrapper of _TCPSend function, see the guide. ; Syntax.........: _TCPSend($iMainsocket, $iData, $iFlag = 0) ; Parameters ....: $iMainsocket - The array as returned by _TCPAccept ; or the connected socket identifier (SocketID) as returned by _TCPConnect. ; $iData - Data sent. ; |Text or binary data ; $iFlag - values can be added together ; |$TCP_DATA_DEFAULT (0) - It doesn't add anything at the end of the string [Default] ; |$TCP_DATA_EOT (2) - It adds an End of Text ASCII character (Chr(3)) at the end of the string ; Return values .: see the guide. ; Author ........: j0kky ; Modified ......: 1.0.0 ; Remarks .......: If Unicode strings need to be transmitted they must be encoded/decoded with StringToBinary()/BinaryToString(). ; $iFlag = $TCP_DATA_EOT must be set in couple with _TCPRecv, so don't use it for external application ; Links .........: send: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740149(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _TCPSend($iMainsocket, $iData, $iFlag = 0) If IsArray($iMainsocket) And (UBound($iMainsocket, 0) = 1) And (UBound($iMainsocket) > 0) Then $iMainsocket = $iMainsocket[0] If BitAND($iFlag, 2) = 2 Then $iData = String($iData) & Chr(3) $iResult = TCPSend($iMainsocket, $iData) Return SetError(@error, 0, $iResult) EndFunc ;==>_TCPSend ; #WRAPPER# ===================================================================================================================== Func _TCPNameToIP($sName) $iResult = TCPNameToIP($sName) Return SetError(@error, 0, $iResult) EndFunc ;==>_TCPNameToIP ; #FUNCTION# ==================================================================================================================== ; Name...........: _GetIps ; Description ...: Get local and public IP address of a network/computer ; Syntax.........: _GetIps($iServerName = "") ; Parameters ....: $iServerName - The server name which can retrieve your public IP ; |For example: "www.something.com/somethingelse" [Default = ""] ; Return values .: On success it returns an array: ; |[0] - Local IP (on LAN) of the adapter used to connect to Internet. ; |[1] - Public IP. ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter (not used) ; |-5 - servers are offline ; |-6 - IP retrieving failed ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Remarks .......: It works with Winsock library, so it must be initialized with _TCPStartup(). ; Local and public IPs are both retrieved through internet. ; Links .........: error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _GetIps($iServerName = "") If $iServerName = Default Then $iServerName = "" $iServerName = String($iServerName) $iServerName = StringRegExpReplace($iServerName, "^http.?://", "") If StringInStr($iServerName, "/") Then If StringRegExp($iServerName, "/(.*)", 1)[0] Then If StringRight($iServerName, 1) = "/" Then $iServerName = StringTrimRight($iServerName, 1) EndIf Else $iServerName &= "/" EndIf If Not StringRegExp($iServerName, ".+\..{2,}") Then $iServerName = "" ; invalid parameter Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0, $sLocalIP = "", $sPublicIP = "" Local $tagSockAddr = "short sin_family; ushort sin_port; " & _ "STRUCT; ulong S_addr; ENDSTRUCT; " & _ ;sin_addr "char sin_zero[8]" Local $hSock = DllCall($hWs2, "uint", "socket", "int", 2, "int", 1, "int", 6); AF_INET, SOCK_STREAM, IPPROTO_TCP If @error Then $bError = -1 ElseIf ($hSock[0] = 4294967295) Or ($hSock[0] = -1) Then ;INVALID_SOCKET $bError = 1 Else $hSock = $hSock[0] EndIf If Not $bError Then If $iServerName Then Local $aGetIPURL[][2] = [["www.myexternalip.com/raw"], ["checkip.dyndns.org/"], ["bot.whatismyipaddress.com/"], [$iServerName]], $nElements = 0 Else Local $aGetIPURL[][2] = [["www.myexternalip.com/raw"], ["checkip.dyndns.org/"], ["bot.whatismyipaddress.com/"]], $nElements = 0 EndIf For $i = 0 To (UBound($aGetIPURL) - 1) $sServerIp = TCPNameToIP(StringRegExp($aGetIPURL[$i][0], "(.*?)/", 1)[0]) If $sServerIp <> "" Then $aGetIPURL[$nElements][0] = $aGetIPURL[$i][0] $aGetIPURL[$nElements][1] = $sServerIp $nElements += 1 EndIf Next If $nElements Then ReDim $aGetIPURL[$nElements][2] Else $bError = 1 $nCode = -5 ;there is no valid server for checking IP EndIf EndIf If Not $bError Then $aRet = DllCall($hWs2, "ushort", "htons", "ushort", 80) If @error Then $bError = -1 Else $iDestPort = $aRet[0] EndIf EndIf If Not $bError Then For $i = 0 To (UBound($aGetIPURL) - 1) $sServerIp = $aGetIPURL[$i][1] If Not $bError Then $aRet = DllCall($hWs2, "int", "ioctlsocket", "uint", $hSock, "long", 0x8004667e, "ulong*", 1) ;FIONBIO If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf EndIf If Not $bError Then $aRet = DllCall($hWs2, "ulong", "inet_addr", "str", $sServerIp) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Or ($aRet[0] = 0) Then ;INADDR_NONE or INADDR_ANY $bError = 1 Else $sServerIp = $aRet[0] EndIf EndIf If Not $bError Then $tSockAddr = DllStructCreate($tagSockAddr) DllStructSetData($tSockAddr, "sin_family", 2) ;AF_INET DllStructSetData($tSockAddr, "sin_port", $iDestPort) DllStructSetData($tSockAddr, "S_addr", $sServerIp) $aRet = DllCall($hWs2, "int", "connect", "uint", $hSock, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR -> functional with connect() on non-blocking sockets $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $bError = -1 ElseIf ($aRet[0] <> 0) And ($aRet[0] <> 10035) Then ;WSAEWOULDBLOCK $bError = 1 EndIf EndIf $tSockAddr = 0 EndIf If Not $bError Then Local $tagFd_set = "uint fd_count; uint fd_array[64]" Local $tFd_set_writefds = DllStructCreate($tagFd_set) DllStructSetData($tFd_set_writefds, "fd_count", 1) DllStructSetData($tFd_set_writefds, "fd_array", $hSock, 1) Local $tFd_set_exceptfds = DllStructCreate($tagFd_set) DllStructSetData($tFd_set_exceptfds, "fd_count", 1) DllStructSetData($tFd_set_exceptfds, "fd_array", $hSock, 1) Local $tTimeval = DllStructCreate("long tv_sec; long tv_usec") DllStructSetData($tTimeval, "tv_sec", Floor(500 / 1000)) DllStructSetData($tTimeval, "tv_usec", Round(Mod(500, 1000) * 1000)) $aRet = DllCall($hWs2, "int", "select", _ "int", $hSock, "ptr", 0, "ptr", DllStructGetPtr($tFd_set_writefds), "ptr", DllStructGetPtr($tFd_set_exceptfds), "ptr", DllStructGetPtr($tTimeval)) If @error Then $bError = -1 ElseIf ($aRet[0] = 0) Or ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Then $bError = 1 Else If Not (DllStructGetData($tFd_set_writefds, "fd_count") = 1) Then $bError = 1 EndIf EndIf If Not $bError And Not $sLocalIP Then $tSockAddr = DllStructCreate($tagSockAddr) $aRet = DllCall($hWs2, "int", "getsockname", "uint", $hSock, "ptr", DllStructGetPtr($tSockAddr), "int*", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 Else $aRet = DllCall($hWs2, "ptr", "inet_ntoa", "ulong", DllStructGetData($tSockAddr, "S_addr")) If @error Then $bError = -1 ElseIf $aRet[0] = Null Then $bError = 1 Else $sLocalIP = DllStructGetData(DllStructCreate("char[15]", $aRet[0]), 1) ;IP address EndIf EndIf $tSockAddr = 0 EndIf If Not $bError Then $sRequest = "GET /" & StringRegExp($aGetIPURL[$i][0], "/(.*)", 1)[0] & " HTTP/1.1" & @CRLF & _ "Host: " & StringRegExp($aGetIPURL[$i][0], "(.*?)/", 1)[0] & @CRLF & _ "Connection: close" & @CRLF & @CRLF TCPSend($hSock, $sRequest) Local $sRecv = "", $hTimer = TimerInit() While 1 $sRecv &= _TCPRecv($hSock, 2048) If @error Or @extended Then If @error Then $bError = 1 ExitLoop EndIf If TimerDiff($hTimer) > 2500 Then ExitLoop Sleep(10) WEnd EndIf If Not $bError Then $aPublicIP = StringRegExp($sRecv, "((?:\d{1,3}\.){3}\d{1,3})", 3) ;STR_REGEXPARRAYGLOBALMATCH If Not @error Then $sPublicIP = $aPublicIP[0] ExitLoop Else $bError = 1 EndIf EndIf If $bError And $i = (UBound($aGetIPURL) - 1) Then $nCode = -6 ExitLoop Else $bError = 0 $nCode = 0 TCPCloseSocket($hSock) EndIf Local $hSock = DllCall($hWs2, "uint", "socket", "int", 2, "int", 1, "int", 6); AF_INET, SOCK_STREAM, IPPROTO_TCP If @error Then $bError = -1 ElseIf ($hSock[0] = 4294967295) Or ($hSock[0] = -1) Then ;INVALID_SOCKET $bError = 1 Else $hSock = $hSock[0] EndIf Next EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf $nReturn = -1 Else Local $nReturn[2] = [$sLocalIP, $sPublicIP] EndIf If $hSock Then TCPCloseSocket($hSock) DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_GetIps ; #MODIFIED WRAPPER# ============================================================================================================ ; Name...........: _TCPCloseSocket ; Description ...: Wrapper of TCPCloseSocket function, see the guide. ; Syntax.........: _TCPCloseSocket($iMainsocket) ; Parameters ....: $iMainsocket - The array as returned by _TCPAccept ; or the connected socket identifier (SocketID) as returned by _TCPListen and _TCPConnect. ; Return values .: see the guide. ; Author ........: j0kky ; Modified ......: 1.0.0 ; Links .........: recv: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740121(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _TCPCloseSocket($iMainsocket) If IsArray($iMainsocket) And (UBound($iMainsocket, 0) = 1) And (UBound($iMainsocket) > 0) Then $iMainsocket = $iMainsocket[0] $iResult = TCPCloseSocket($iMainsocket) Return SetError(@error, 0, $iResult) EndFunc ;==>_TCPCloseSocket ; #WRAPPER# ===================================================================================================================== Func _TCPShutdown() $iResult = TCPShutdown() Return SetError(@error, 0, $iResult) EndFunc ;==>_TCPShutdown ; #WRAPPER# ===================================================================================================================== Func _UDPStartup() $iResult = UDPStartup() Return SetError(@error, 0, $iResult) EndFunc ;==>_UDPStartup ; #FUNCTION# ==================================================================================================================== ; Name...........: _UDPBind ; Description ...: Creates and bind a socket to a local IP and a local port. ; Syntax.........: _UDPBind($sSourceAddr = "", $iSourcePort = 0) ; Parameters ....: $sSourceAddr - Source IP ; |Internet Protocol dotted address(IpV4) as "192.162.1.1". [Default = ""] ; $iSourcePort - Source port. ; |1 : 65534 - port on which the created socket will be bind (on the local PC). [Default = 0] ; Return values .: On success it returns the main socket identifier. ; |Any value > 0 ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Remarks .......: It could be used before both of _UDPSendTo (client app) and _UDPRecvFrom (server app) functions ; Links .........: bind: https://msdn.microsoft.com/en-us/library/windows/desktop/ms737550(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _UDPBind($sSourceAddr = "", $iSourcePort = 0) If $sSourceAddr = Default Then $sSourceAddr = "" If $iSourcePort = Default Then $iSourcePort = 0 $sSourceAddr = String($sSourceAddr) $iSourcePort = Number($iSourcePort) If Not ($iSourcePort >= 0 And $iSourcePort < 65535) Then Return SetError(-4, 0, -1) ; invalid parameter If $sSourceAddr <> "" Then StringRegExp($sSourceAddr, "((?:\d{1,3}\.){3}\d{1,3})", 3) ;$STR_REGEXPARRAYGLOBALMATCH If @error Then Return SetError(-4, 0, -1) EndIf Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0 Local $tagSockAddr = "short sin_family; ushort sin_port; " & _ "STRUCT; ulong S_addr; ENDSTRUCT; " & _ ;sin_addr "char sin_zero[8]" Local $hSock = DllCall($hWs2, "uint", "socket", "int", 2, "int", 2, "int", 17); AF_INET, SOCK_DGRAM, IPPROTO_UDP If @error Then $bError = -1 ElseIf ($hSock[0] = 4294967295) Or ($hSock[0] = -1) Then ;INVALID_SOCKET $bError = 1 Else $hSock = $hSock[0] EndIf If (Not $bError) And ($sSourceAddr <> "") Then $aRet = DllCall($hWs2, "ulong", "inet_addr", "str", $sSourceAddr) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Or ($aRet[0] = 0) Then ;INADDR_NONE or INADDR_ANY $bError = 1 Else $sSourceAddr = $aRet[0] EndIf EndIf If (Not $bError) And $iSourcePort Then $aRet = DllCall($hWs2, "ushort", "htons", "ushort", $iSourcePort) If @error Then $bError = -1 Else $iSourcePort = $aRet[0] EndIf EndIf If Not $bError Then $tSockAddr = DllStructCreate($tagSockAddr) DllStructSetData($tSockAddr, "sin_family", 2) ;AF_INET If $iSourcePort Then DllStructSetData($tSockAddr, "sin_port", $iSourcePort) Else DllStructSetData($tSockAddr, "sin_port", 0) EndIf If $sSourceAddr Then DllStructSetData($tSockAddr, "S_addr", $sSourceAddr) Else DllStructSetData($tSockAddr, "S_addr", 0x00000000) ;INADDR_ANY EndIf $aRet = DllCall($hWs2, "int", "bind", "uint", $hSock, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf $tSockAddr = 0 EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure If $hSock Then UDPCloseSocket($hSock) ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf $nReturn = -1 If $hSock Then UDPCloseSocket($hSock) Else $nReturn = $hSock EndIf DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_UDPBind ; #FUNCTION# ==================================================================================================================== ; Name...........: _UDPSendTo ; Description ...: Sends data to an address/port, it uses a socket created by _UDPBind or it creates a socket itself ; Syntax.........: _UDPSendTo($sIPAddr, $iDestPort, $iData, $iMainsocket = 0) ; Parameters ....: $sIPAddr - Destination IP. ; |Internet Protocol dotted address(IpV4) as "192.162.1.1". ; $iDestPort - Destination port. ; |1 : 65534 - port which the created socket will connect on. ; $iData - Data sent. ; |Text or binary data ; $iMainsocket - Main socket identifier returned by _UDPBind. ; |Any value > 0 [Default = 0] ; Return values .: On success it returns an array: ; |[0] - The number of bytes sent. ; |[1] - The main socket identifier used. ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Links .........: sendto: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740148(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _UDPSendTo($sIPAddr, $iDestPort, $iData, $iMainsocket = 0) If $iMainsocket = Default Then $iMainsocket = 0 $iMainsocket = Number($iMainsocket) $sIPAddr = String($sIPAddr) $iDestPort = Number($iDestPort) If Not IsBinary($iData) Then $iData = String($iData) If Not ($iDestPort > 0 And $iDestPort < 65535) Or _ $iMainsocket < 0 Then Return SetError(-4, 0, -1) ; invalid parameter StringRegExp($sIPAddr, "((?:\d{1,3}\.){3}\d{1,3})", 3) ;$STR_REGEXPARRAYGLOBALMATCH If @error Then Return SetError(-4, 0, -1) Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0 Local $tagSockAddr = "short sin_family; ushort sin_port; " & _ "STRUCT; ulong S_addr; ENDSTRUCT; " & _ ;sin_addr "char sin_zero[8]" If Not $iMainsocket Then Local $aRet = DllCall($hWs2, "uint", "socket", "int", 2, "int", 2, "int", 17); AF_INET, SOCK_DGRAM, IPPROTO_UDP If @error Then $bError = -1 ElseIf ($aRet[0] = 4294967295) Or ($aRet[0] = -1) Then ;INVALID_SOCKET $bError = 1 Else $iMainsocket = $aRet[0] EndIf EndIf If Not $bError Then $aRet = DllCall($hWs2, "ulong", "inet_addr", "str", $sIPAddr) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Or ($aRet[0] = 0) Then ;INADDR_NONE or INADDR_ANY $bError = 1 Else $sIPAddr = $aRet[0] EndIf EndIf If Not $bError Then $aRet = DllCall($hWs2, "ushort", "htons", "ushort", $iDestPort) If @error Then $bError = -1 Else $iDestPort = $aRet[0] EndIf EndIf If Not $bError Then $aRet = DllCall($hWs2, "int", "ioctlsocket", "uint", $iMainsocket, "long", 0x8004667e, "ulong*", 1) ;FIONBIO If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf EndIf If Not $bError Then Local $tSockAddr = DllStructCreate($tagSockAddr) DllStructSetData($tSockAddr, "sin_family", 2) ;AF_INET DllStructSetData($tSockAddr, "sin_port", $iDestPort) DllStructSetData($tSockAddr, "S_addr", $sIPAddr) Local $nLenght, $tBuf If IsBinary($iData) Then $nLenght = BinaryLen($iData) $tBuf = DllStructCreate("byte[" & $nLenght & "]") DllStructSetData($tBuf, 1, $iData) Else $nLenght = StringLen($iData) $tBuf = DllStructCreate("char[" & $nLenght & "]") DllStructSetData($tBuf, 1, $iData) EndIf $aRet = DllCall($hWs2, "int", "sendto", _ "uint", $iMainsocket, "ptr", DllStructGetPtr($tBuf), "int", $nLenght, "int", 0, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Then ;SOCKET_ERROR $bError = 1 Else Local $aReturn[2] = [$aRet[0], $iMainsocket] EndIf EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf $nReturn = -1 Else $nReturn = $aReturn EndIf DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_UDPSendTo ; #FUNCTION# ==================================================================================================================== ; Name...........: _UDPRecvFrom ; Description ...: Receives data from a bound socket on the local PC. ; Syntax.........: _UDPRecvFrom($iMainsocket, $iMaxLen, $iFlag = 0) ; Parameters ....: $iMainsocket - Main socket identifier. ; |Any value > 0 ; $iMaxLen - Max # of characters to receive (usually 2048). ; $iFlag ; |0 - Text data. [Default] ; |1 - Binary data. ; Return values .: On success it returns an array: ; |[0] - The data received. ; |[1] - The IP address of the sender. ; |[2] - The port used by the sender for connection. ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Links .........: recvfrom: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740120(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _UDPRecvFrom($iMainsocket, $iMaxLen, $iFlag = 0) If $iFlag = Default Then $iFlag = 0 $iMainsocket = Number($iMainsocket) $iMaxLen = Number($iMaxLen) $iFlag = Number($iFlag) If $iMainsocket < 0 Or _ $iMaxLen < 1 Or _ Not ($iFlag = 0 Or $iFlag = 1) Then Return SetError(-4, 0, -1) ; invalid parameter Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0 Local $tagSockAddr = "short sin_family; ushort sin_port; " & _ "STRUCT; ulong S_addr; ENDSTRUCT; " & _ ;sin_addr "char sin_zero[8]" If Not $bError Then $aRet = DllCall($hWs2, "int", "ioctlsocket", "uint", $iMainsocket, "long", 0x8004667e, "ulong*", 1) ;FIONBIO If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf EndIf Local $tSockAddr = DllStructCreate($tagSockAddr) Local $tBuf If $iFlag Then $tBuf = DllStructCreate("byte[" & $iMaxLen & "]") Else $tBuf = DllStructCreate("char[" & $iMaxLen & "]") EndIf $aRet = DllCall($hWs2, "int", "recvfrom", _ "uint", $iMainsocket, "ptr", DllStructGetPtr($tBuf), "int", $iMaxLen, "int", 0, "ptr", DllStructGetPtr($tSockAddr), "int*", DllStructGetSize($tSockAddr)) If @error Then $bError = -1 ElseIf ($aRet[0] = -1) Or ($aRet[0] = 4294967295) Then ;SOCKET_ERROR $bError = 1 $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $bError = -1 ElseIf $aRet[0] = 0 Or $aRet[0] = 10035 Then ;WSAEWOULDBLOCK $nCode = -10 ;internal function value, it means no error EndIf Else Local $aResult[3] = [DllStructGetData($tBuf, 1)] ;data $aRet = DllCall($hWs2, "ptr", "inet_ntoa", "ulong", DllStructGetData($tSockAddr, "S_addr")) If @error Then $bError = -1 ElseIf $aRet[0] = Null Then $bError = 1 Else $aResult[1] = DllStructGetData(DllStructCreate("char[15]", $aRet[0]), 1) ;IP address $aRet = DllCall($hWs2, "ushort", "ntohs", "ushort", DllStructGetData($tSockAddr, "sin_port")) If @error Then $bError = -1 Else $aResult[2] = $aRet[0] ;port EndIf EndIf EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf If $nCode = -10 Then $nCode = 0 $nReturn = -1 Else $nReturn = $aResult EndIf DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_UDPRecvFrom ; #FUNCTION# ==================================================================================================================== ; Name...........: _UDPCloseSocket ; Description ...: Close a UDP socket. ; Syntax.........: _UDPCloseSocket($iMainsocket) ; Parameters ....: $iMainsocket - Main socket identifier returned by _UDPBind or the array returned by _UDPSendTo. ; |Any value > 0 ; Return values .: On success it returns 1. ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |-4 - invalid parameter ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: j0kky ; Modified ......: 1.0.0 ; Links .........: closesocket: https://msdn.microsoft.com/en-us/library/windows/desktop/ms737582(v=vs.85).aspx ; error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx ; =============================================================================================================================== Func _UDPCloseSocket($iMainsocket) If IsArray($iMainsocket) Then If Not ((UBound($iMainsocket, 0) = 1) And (UBound($iMainsocket) = 2)) Then Return SetError(-1, 0, -4) $iMainsocket = $iMainsocket[1] Else If $iMainsocket < 1 Then Return SetError(-1, 0, -4) EndIf Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0 $aRet = DllCall($hWs2, "int", "closesocket", "uint", $iMainsocket) If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf $nReturn = -1 Else $nReturn = 1 EndIf DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_UDPCloseSocket ; #WRAPPER# ===================================================================================================================== Func _UDPShutdown() $iResult = UDPShutdown() Return SetError(@error, 0, $iResult) EndFunc ;==>_UDPShutdown Obviously there can be a lot of errors, so please report here any problem\suggestion! Updated to: 11/01/16 winsock.zip
    1 point
  11. @iamthekey - As Goldberg'ish as that is I would never have thought of using stringsplit like that. Bravo!
    1 point
  12. Hello tiye0405, I've attached the imagesearch files below. Follow this video so you install the dll into your system. For the example script above I would move them to this folder and include this piece of code at the top. Let me know if you don't get it working. #include <ImageSearch2015.au3> ImageSearch2015.zip
    1 point
  13. I actually didn't remember but see now how right I was in that last post... fuck it. Jos
    1 point
  14. Regular expressions do exactly this Example : $str = "What I need to have happen is to then to go back ... and extract the number 75,689 that is listed in each string." $nbr = StringRegExp($str, '\d+(?:,\d+)?', 1) If IsArray($nbr) Then Msgbox(0,"", $nbr[0]) This code can be adapted so you might provide sample strings
    1 point
  15. Jon

    AutoIt v3.3.14.3 Released

    AutoIt v3.3.14.3 has been released. Thanks to everyone involved, both visible and behind the scenes. Download it here. Complete list of changes: History
    1 point
  16. doudou

    SOAP and AutoIT

    Yeah, why simple if you can do complicated?! Manually establishing SOAP session by fiddling with XML is the last thing you should do, if there is a library for exactly this purpose. Ah? What are you talking about? The sample may lack error handling but it is WORKING and a good start. Have you tried it out at all? Do so before bashing other people who try to help.
    1 point
  17. Jos

    Input Only Uppercase

    $Input_1 = GuiCtrlCreateInput("", 90, 100, 130, 30,$ES_UPPERCASE)
    1 point
×
×
  • Create New...