Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/17/2019 in all areas

  1. Just uploaded the latest beta version which now has all these changes applied: - 19.102.1901.8-11 Changes to allow the program to be run by other editors. - 19.102.1901.12 Updates Stop and Restartconsole message to indicate in case the HotKeys aren't set in case of second instance HotKeys are ony set when the Editor program has the focus to allow for multiple instances. - 19.102.1901.13 Updated _RefreshSystemTray, which wasn't working anymore since a long time - 19.102.1901.14 Added WinClose for the Shelled Script to nicely close that process before ultimately killing it when still needed. This avoids having dead icon in systemtray. Jos
    3 points
  2. pixelsearch

    CSV file editor

    Hi everybody The script below (901f) allows to wander easily through a listview, selecting any item or subitem by using the 4 direction keys. The Enter key is also managed and allows to fire an event (as double-click does) With the help of mikell (many thanks !) and after several tests based on 1000 rows & 6 columns, we succeeded to code a clear WM_NOTIFY function, which is simple (though solid) and should be reusable without any modification in other scripts dealing with basic listviews (we didn't use or check any particular style for the listview) Trapping the Enter key has been done by using a dummy control + Accelerators, though we spent the whole last week trapping it in another way, using Yashied's Wsp.dll (without any problem) . Finally we choosed the dummy control option... to have a smaller code. Version 901f (Nov 11, 2019) : the pic below shows how the selected subitem appears, with its specific background colour (light blue) Version 901f code : #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <WinAPIvkeysConstants.au3> Global $hGUI = GUICreate("Wandering through ListView (901f)", 460, 500) Global $idListView = GUICtrlCreateListView _ (" Col 0 | Col 1| Col 2| Col 3", 15, 60, 430, 400) Global $hListView = GuiCtrlGetHandle($idListView) For $iRow = 0 To 99 $sRow = StringFormat("%2s", $iRow) GUICtrlCreateListViewItem( _ "Row " & $sRow & " / Col 0 |" & _ "Row " & $sRow & " / Col 1 |" & _ "Row " & $sRow & " / Col 2 |" & _ "Row " & $sRow & " / Col 3", $idListView) Next Global $g_iColumnCount = _GUICtrlListView_GetColumnCount($idListView) -1 Global $g_iItem = -1, $g_iSubItem = -1 ; item/subitem selected in ListView control Global $idDummy_Dbl_Click = GUICtrlCreateDummy() Global $idDummy_Enter = GUICtrlCreateDummy() Global $aAccelKeys[1][2] = [["{ENTER}", $idDummy_Enter]] GUISetAccelerators($aAccelKeys) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hGUI) Exit Case $idDummy_Dbl_Click MsgBox($MB_TOPMOST, "Double-click activated cell", _ "Row " & $g_iItem & " / Col " & $g_iSubItem) Case $idDummy_Enter If _WinAPI_GetFocus() = $hListView And $g_iItem > -1 Then MsgBox($MB_TOPMOST, "Enter activated cell", _ "Row " & $g_iItem & " / Col " & $g_iSubItem) EndIf EndSwitch WEnd ;============================================ Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $hWndFrom, $iIDFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Static $bMouseDown = False, $bNotXP = Not (@OSVersion = "WIN_XP") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $iColor = 0xFF000000 ; this is $CLR_DEFAULT in ColorConstants.au3 If $iItem = $g_iItem And $iSubItem = $g_iSubItem Then $iColor = 0xFFFFC0 ; light blue for 1 subitem (BGR) EndIf DllStructSetData($tCustDraw, "clrTextBk", $iColor) Return $CDRF_NEWFONT Case $LVN_KEYDOWN If $bMouseDown Or $g_iItem = -1 Then Return 1 ; don't process Local $tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam) Local $iVK = DllStructGetData($tInfo, "VKey") Switch $iVK Case $VK_RIGHT If $g_iSubItem < $g_iColumnCount Then $g_iSubItem += 1 If $bNotXP Then _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_LEFT If $g_iSubItem > 0 Then $g_iSubItem -= 1 If $bNotXP Then _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_SPACE ; spacebar would select the whole row Return 1 EndSwitch Case $NM_RELEASEDCAPTURE $bMouseDown = True Local $iItemSave = $g_iItem Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) $g_iItem = $aHit[0] $g_iSubItem = $aHit[1] If $g_iItem = -1 And $iItemSave > -1 Then _GUICtrlListView_RedrawItems($hListview, $iItemSave, $iItemSave) EndIf Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Local $iNewState = DllStructGetData($tInfo, "NewState") Switch $iNewState Case BitOr($LVIS_FOCUSED, $LVIS_SELECTED) $g_iItem = DllStructGetData($tInfo, "Item") _GUICtrlListView_SetItemSelected($hListview, $g_iItem, False) EndSwitch Case $NM_CLICK, $NM_RCLICK $bMouseDown = False Case $NM_DBLCLK $bMouseDown = False If $g_iItem > -1 Then GUICtrlSendToDummy($idDummy_Dbl_Click) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Version 901k (Dec 16, 2019) What started with a simple "wander through listview" has turned now to a functional CSV file editor, which can be useful to modify your CSV files with AutoIt : Here are the instructions to use the script, based on a CSV file starting like this : street,city,zip,state,beds,baths,sq__ft,type,sale_date,price,latitude,longitude 3526 HIGH ST,SACRAMENTO,95838,CA,2,1,836,Residential,Wed May 21 00:00:00 EDT 2008,59222,38.631913,-121.434879 51 OMAHA CT,SACRAMENTO,95823,CA,3,1,1167,Residential,Wed May 21 00:00:00 EDT 2008,68212,38.478902,-121.431028 ... 1) Import options : comma delimited (default) No need to change anything if your CSV is comma delimited (other options are Semicolon delimited, Tab delimited) 2) Import options : First row = headers (default = checked) * Keep it checked if the 1st row of your imported file contains headers (that's the case in our example) * UNcheck it if the 1st row contains data, making listview headers appear like this : Col 0 | Col 1 | Col 2 ... 3) Import your CSV file : Only now the listview will be created dynamically. As soon as it is populated, GUI becomes resizable/maximizable, which can be helpful during modifications of a listview containing many columns. 4) Selection color : light blue (default) You can change the selected cell background color by clicking the "Selection color" button : this will open Windows color picker. 5) Editing a listview cell : done by Enter key (or double-click), this is how the edited cell will appear : * Please note that the edited background color (green in the pic) depends on each computer theme. It is not related to the selected background we discussed in 4) * Validate your modification with Enter key, or cancel the modification (revert) with Escape Key 6) Edit Font size : 15 (default) 15 was good in the precedent pic, the edited cell had its content "RIO LINDA" perfectly aligned with all other cells (on my computer). Here again, the font height required depends on each computer : if you want the edited font to be bigger (or smaller), just use the updown control. 7) Chained Edit ? (default = No) * "No" => when you finish editing a cell (Enter key), the same cell stays selected. * "Horizontally" => If checked, edition will automatically continue with the cell on its right. * "Vertically" => If checked, edition will automatically continue with the cell below. This feature can be very useful when you modify cells of a whole colum (vertically) or cells by row (horizontally) 8 ) Inserting a blank line (not in Gui) : press the "Ins" key : 9) Deleting a line (not in Gui) : press the "Del" key : 10) Export CSV file : Filename automatically suggested for export will be : Filename import & actual date & actual time, for example : Import name = "Sales Results.csv" => suggested Export name = "Sales Results_2019-12-16 16:00:59.csv" Version 901m (Dec 18, 2019) Yesterday, mikell suggested to import the csv file by dropping it directly into the GUI, good idea This new version 901m allows it. Now there are 2 ways to import the csv file : * Import button * Drag and drop into the large droppable zone, as shown in the pic below (this zone will be reused to create the listview at same coords) Version 901n (Dec 20, 2019) As t0nZ got tons of csv files, pipe "|" separated, here is a new version allowing this 4th separator Version 901p (Dec 25, 2019) New functionality : now you can drag headers to reorder columns. It may help some users who need it while editing their file. Exported CSV file will be saved according to the new columns order. Version 901r (Dec 29, 2019) New functionality : Numeric sort on any column (right click on column header) It is recommended to backup (export) your file before sorting, just in case you need a copy of it, unsorted. Version 901s (Dec 30, 2019) 1 functionality added : String sort (right click on column header) Numeric sort is alright in most cases, but sometimes we also need a String sort like shown in the following picture. Both ways of sorting (numeric and string) are found in this new release. Version 901t (Jan 3, 2020) 3 functionalities added Rename Header , Insert Column , Delete Column (right click on column header to display its context menu) Version 901u (Jan 6, 2020) 1 functionality added : Natural sort. Thanks to jchd for the idea and Melba23 for his function ArrayMultiColSort() included in the script. Though this natural sort isn't fully implemented, it should work when numbers precede letters (see pic below or better, try it on the "street" column found in the downloadable csv test file below) Natural sort duration + listview update are fast, maybe because of the new function _BufferCreate() described here and now added to the script. Version 901w (Jan 10, 2020) Two functionalities added : 1) Close File button, which allows to import other csv file(s) during the same session 2) Import speed has been improved because the listview control is now populated directly by an Array and not anymore by GUICtrlCreateListViewItem() This explains why, in this version, there are no more Control id's for listview items, allowing to empty the listview content in a snap with this line of code : _SendMessage($g_hListView, $LVM_DELETEALLITEMS) That's what it took to add the Close File button and import several csv files during the same session, avoiding id leaks. Please report if any issue is encountered. Version 901x (Jan 14, 2020) One minor functionality added : number of rows is now displayed just under the listview, it may be handy sometimes. Other minor changes included (natural sort speed improved) Credits : Many thanks to Czardas for his function _CSVSplit() and guinness for his function _SaveCSV(), guys you did a great job. Thanks to Musashi : your suggestions and time passed on testing beta versions of the script, that was really helpful and challenging. Not sure I would have ended this script without your detailed reports. Mikell : the 1st step above (901f) that we wrote together, it all started from here. Your knowledge and kindness are legendary ! Not forgetting all other persons who were inspiring : LarsJ, Melba23, jpm, that list could be endless... Download link : version 901x - Jan 14, 2020 (minor update on Jan 15) 901x - CSV file editor.au3 Test csv file (986 rows/12cols) : Sacramento real estate transactions.csv
    1 point
  3. I guess the answer to your question is yes. One can put executable code into memory and execute it. Of course that code would have to be executable, like a DLL with entry points to functions or some other executable machine code. There are several UDFs, that I'm aware of, that use that technique. One that comes to mind immediately is the JSON.au3 UDF. There are even some UDFs that aid in allowing one to run code from memory. If you want more information on that subject, I suggest you search the forum for it and study the relevant UDFs that you find. I have no idea why the author of that function had to, or chose to, use CallWindowProc, in the User32,dll, to supposedly call a RC4 cipher routine. Without digging into the snippet, using that particular function for that particular purpose makes no sense to me. I hope that helps.
    1 point
  4. Not sure I understand because I am not switching off anything, just doing some code cleanup and looking at things that are on my "checklist" since a while. Just finished fixing the _RefreshSystemTray() Function as that was clearly not working anymore since a while and all dead icons were left in the System tray. Jos
    1 point
  5. @Professor_Bernd, I've played a little with the logic in Autoit3Wrapper for HotKeySet() and now only enable the HotKeys when the Editor that was used to start Autoit3 has the focus in the latest Beta version. This allows multiple instances of Autoit3Wrapper in case one wants to test 2 scripts at the same time. Jos
    1 point
  6. You can read registry like this : #include <Constants.au3> Opt("MustDeclareVars", 1) RunBrowser() ; return PID of the process Func RunBrowser() Local $sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", "") If Not @error Then Return Run($sPath) $sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE", "") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "No browser available") Return Run($sPath) EndFunc ;==>RunBrowser
    1 point
  7. Moved to the appropriate forum. Moderation Team
    1 point
  8. Hi jugador With the help of mikell, we scripted a simple but solid WM_NOTIFY function in a thread called "Wandering through ListView" It allows to select any item or subitem by using the 4 direction keys in a basic Listview. The Enter key is also managed. The function can be reused in other scripts without modification, depending on everyone's need. If you got questions about the function, don't hesitate to ask them in the other thread (found in 'AutoIt Example Scripts')
    1 point
  9. $sVar = "Test_Window - Notepad" $hWnd = WinGetHandle($sVar) If WinExists("[CLASS:Notepad]") And WinGetTitle($hWnd) = $sVar Then MsgBox(64, "", "it's there") EndIf
    1 point
  10. once you got the table, you have to use data directly from the array. try this: #include <IE.au3> #include <Array.au3> Local $oIE = _IEAttach("Shop") $oTable = _IETableGetCollection($oIE, 14) Local $aTableData = _IETableWriteToArray($oTable, True) MsgBox(0, "row one column one", $aTableData[1][1]) MsgBox(0, "row one column two", $aTableData[1][2]) For $i = 0 To UBound($aTableData) - 1 MsgBox(0, "", $aTableData[$i][1] & " - " & $aTableData[$i][2]) ; ConsoleWrite($aTableData[$i][1] & " - " & $aTableData[$i][2] & @CRLF) ; <-- this is better Next
    1 point
  11. You can use... or get the code from here... '?do=embed' frameborder='0' data-embedContent>> 8)
    1 point
  12. cunningt

    Ping help

    We encountered this exact same problem in our organization, so I had to resort to using a custom ICMP payload function within my AutoIt scripts based upon code from german AutoIt forums. Our network team enabled the McAfee IPS this week. Our network support staff worked directly with McAfee and I don't know the technical details but the bottom line was McAfee wasn't able to allow AutoIt's ping packets but at the same time still block Nachi-like activity - if they made an allowance for AutoIt's native pings then Nachi-like packets could still get through. So I had no choice but to send custom ICMP payloads from within AutoIt in order to mimic Windows' native ping payloads (I compared the native ping payloads of WinXP and Win7 and they were the exact same). Sure I could execute ping.exe but I opted to do this natively within AutoIt instead, for detailed error codes. Some day, could it hurt if AutoIt sent pings the same way that Windows' natively does? Just a suggestion. While troubleshooting this, I customized the ICMP payload to match the 32-byte length of Windows pings but still used repeating ª characters that AutoIt uses; this resulted in the McAfee IPS still blocking the packet... so it wasn't only a packet length issue, it was triggering on the repeating ª characters too. I call the _PingLikeMicrosoft() function in the PingLikeMicrosoft.au3 include file below which contains an example at the top (sorry, wasn't able to figure out how to upload/attach content), which sends this payload: abcdefghijklmnopqrstuvwabcdefghi In any case, thank you AutoIt team... *amazing* work. Cheers. #cs MIMIC MICROSOFT WINDOWS PING PAYLOADS Original AutoIt source from German AutoIt forum: (which was based on Visual Basic source below) http://www.autoit.de/index.php?page=Thread&postID=57929 Original Visual Basic source: http://vbnet.mvps.org/index.html?code/internet/ping.htm MSDN - IcmpSendEcho function http://msdn.microsoft.com/en-us/library/windows/desktop/aa366050%28v=vs.85%29.aspx AutoIt forum: Identical problem with McAfee IPS where it blocks AutoIt's own pings, which are seen as a Nachi-like attack: http://www.autoitscript.com/forum/topic/129525-ping-help/ ;################# ; EXAMPLE - begin ;################# #include "PingLikeMicrosoft.au3" $pingresult = _PingLikeMicrosoft("hostname.somewhere.com", 4000) ; When the function fails, @error contains extended information: ; 1 = Host is offline ; 2 = Host is unreachable ; 3 = Bad destination ; 4 = Other errors If @error Then MsgBox(0, "Ping Result", "Failed" & @CRLF & "Error code: " & @extended) Else MsgBox(0, "Ping Result", "Success" & @CRLF & $pingresult & " milliseconds") EndIf Exit ;################# ; EXAMPLE - end ;################# #ce #include-once #include <WinAPI.au3> Global Const $IP_SUCCESS = 0 Global Const $IP_STATUS_BASE = 11000 Global Const $IP_BUF_TOO_SMALL = ($IP_STATUS_BASE + 1) Global Const $IP_DEST_NET_UNREACHABLE = ($IP_STATUS_BASE + 2) Global Const $IP_DEST_HOST_UNREACHABLE = ($IP_STATUS_BASE + 3) Global Const $IP_DEST_PROT_UNREACHABLE = ($IP_STATUS_BASE + 4) Global Const $IP_DEST_PORT_UNREACHABLE = ($IP_STATUS_BASE + 5) Global Const $IP_NO_RESOURCES = ($IP_STATUS_BASE + 6) Global Const $IP_BAD_OPTION = ($IP_STATUS_BASE + 7) Global Const $IP_HW_ERROR = ($IP_STATUS_BASE + 8) Global Const $IP_PACKET_TOO_BIG = ($IP_STATUS_BASE + 9) Global Const $IP_REQ_TIMED_OUT = ($IP_STATUS_BASE + 10) Global Const $IP_BAD_REQ = ($IP_STATUS_BASE + 11) Global Const $IP_BAD_ROUTE = ($IP_STATUS_BASE + 12) Global Const $IP_TTL_EXPIRED_TRANSIT = ($IP_STATUS_BASE + 13) Global Const $IP_TTL_EXPIRED_REASSEM = ($IP_STATUS_BASE + 14) Global Const $IP_PARAM_PROBLEM = ($IP_STATUS_BASE + 15) Global Const $IP_SOURCE_QUENCH = ($IP_STATUS_BASE + 16) Global Const $IP_OPTION_TOO_BIG = ($IP_STATUS_BASE + 17) Global Const $IP_BAD_DESTINATION = ($IP_STATUS_BASE + 18) Global Const $IP_ADDR_DELETED = ($IP_STATUS_BASE + 19) Global Const $IP_SPEC_MTU_CHANGE = ($IP_STATUS_BASE + 20) Global Const $IP_MTU_CHANGE = ($IP_STATUS_BASE + 21) Global Const $IP_UNLOAD = ($IP_STATUS_BASE + 22) Global Const $IP_ADDR_ADDED = ($IP_STATUS_BASE + 23) Global Const $IP_GENERAL_FAILURE = ($IP_STATUS_BASE + 50) Global Const $MAX_IP_STATUS = ($IP_STATUS_BASE + 50) Global Const $IP_PENDING = ($IP_STATUS_BASE + 255) Global Const $PING_TIMEOUT = 500 Global Const $WS_VERSION_REQD = 0x101 Global Const $MIN_SOCKETS_REQD = 1 Global Const $SOCKET_ERROR = -1 Global Const $INADDR_NONE = 0xFFFFFFFF Global Const $MAX_WSADescription = 256 Global Const $MAX_WSASYSStatus = 128 If @AutoItX64 Then Exit 0 * MsgBox(16, @ScriptName & " - Error", "ICMP structures only designed for 32-Bit Version") Global Const $ICMP_OPTIONS = _ "ubyte Ttl;" & _ "ubyte Tos;" & _ "ubyte Flags;" & _ "ubyte OptionsSize;" & _ "ptr OptionsData" ; Options Data Global Const $tagICMP_ECHO_REPLY = _ "ulong Address;" & _ ; IPAddr "ulong Status;" & _ "ULONG RoundTripTime;" & _ "USHORT DataSize;" & _ "USHORT Reserved;" & _ "ptr Data;" & _ $ICMP_OPTIONS Func _IcmpCustomPayload($sAddress, $sDataToSend, ByRef $ECHO, $PING_TIMEOUT = 4000) ; ECHO As ICMP_ECHO_REPLY ; $ECHO receives an ICMP_ECHO_REPLY on success ; by Prog@ndy, used VBSource from http://vbnet.mvps.org/index.html?code/internet/ping.htm ; on success return 1 , else 0 Local $return = 0, $error = 0 ;~ 'If Ping succeeds : ;~ '.RoundTripTime = time in ms for the ping to complete, ;~ '.Data is the data returned (NULL terminated) ;~ '.Address is the Ip address that actually replied ;~ '.DataSize is the size of the string in .Data ;~ '.Status will be 0 ;~ ' ;~ 'If Ping fails .Status will be the error code Local $WSOCK32DLL = DllOpen("wsock32.dll") ; use Icmp.dll for: Windows 2000 Server and Windows 2000 Professional ;Local $ICMPDLL = DllOpen("icmp.dll") ; use Iphlpapi.dll for: Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP Local $ICMPDLL = DllOpen("Iphlpapi.dll") Local $hPort ;As Long Local $dwAddress ;As Long Local $INADDR_NONE = -1 If Not StringRegExp($sAddress,"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}") Then TCPStartup() $sAddress = TCPNameToIP($sAddress) TCPShutdown() EndIf ;~ 'convert the address into a long representation $dwAddress = DllCall($WSOCK32DLL, "uint", "inet_addr", "str", $sAddress) $dwAddress = $dwAddress[0] ;~ 'if a valid address.. If $dwAddress <> $INADDR_NONE Or $sAddress = "255.255.255.255" Then ;~ 'open a port $hPort = DllCall($ICMPDLL, "hwnd", "IcmpCreateFile") $hPort = $hPort[0] ;~ 'and if successful, If $hPort Then $ECHO = DllStructCreate($tagICMP_ECHO_REPLY & ";char[355]") ;~ 'ping it. Local $ret = _IcmpSendEcho($hPort, _ $dwAddress, _ $sDataToSend, _ StringLen($sDataToSend), _ 0, _ DllStructGetPtr($ECHO), _ DllStructGetSize($ECHO), _ $PING_TIMEOUT, _ $ICMPDLL) ;~ 'return the status as ping succes and close $error = DllStructGetData($ECHO, "Status") If $error = $IP_SUCCESS Then $return = 1 DllCall($ICMPDLL, "uint", "IcmpCloseHandle", "hwnd", $hPort) EndIf Else ;~ 'the address format was probably invalid $return = 0 $error = $INADDR_NONE EndIf DllClose($WSOCK32DLL) DllClose($ICMPDLL) Return SetError($error, 0, $return) EndFunc ;==>_IcmpCustomPayload ; by BugFix, modified by Prog@ndy ; für 1000 < @error < 1004 is der error von Dllcall. Die DllCall-Fehlernummer ist dabei @error/1000 Func _IcmpSendEcho($IcmpHandle, $DestinationAddress, $RequestData, $RequestSize, $RequestOptions, $ReplyBuffer, $ReplySize, $Timeout, $ICMPDLL = "icmp.dll") Local $ret = DllCall($ICMPDLL, "dword", "IcmpSendEcho", _ "hwnd", $IcmpHandle, _ "uint", $DestinationAddress, _ "str", $RequestData, _ "dword", $RequestSize, _ "ptr", $RequestOptions, _ "ptr", $ReplyBuffer, _ "dword", $ReplySize, _ "dword", $Timeout) If @error Then Return SetError(@error+1000, 0, 0) Return $ret[0] EndFunc ;==>_IcmpSendEcho Func _PingLikeMicrosoft($DestinationAddress, $Timeout = 4000) ; function created by CUNNINGT Local $ECHORet ; mimic AutoIt's ping payload, 36 byte payload = FAILED - blocked by IPS and ping timeout ;Local $pingSucess = _IcmpCustomPayload($DestinationAddress, "ªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªª", $ECHORet, $Timeout) ; mimic AutoIt's ping payload, but 32 byte payload like Microsoft's length = FAILED - blocked by IPS and ping timeout ;Local $pingSucess = _IcmpCustomPayload($DestinationAddress, "ªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªª", $ECHORet, $Timeout) ; mimic Windows' ping payload, 32 bytes = SUCCESS - not blocked by IPS Local $pingSucess = _IcmpCustomPayload($DestinationAddress, "abcdefghijklmnopqrstuvwabcdefghi", $ECHORet, $Timeout) If @error Then Switch @error Case $IP_REQ_TIMED_OUT Return SetError(1, 1) Case $IP_DEST_HOST_UNREACHABLE Return SetError(1, 2) Case $IP_BAD_DESTINATION Return SetError(1, 3) Case Else Return SetError(1, 4) EndSwitch Else Return DllStructGetData($ECHORet, "RoundTripTime") EndIf #cs Func _DecIPToString($DecIP) Local $IPString = DllCall("ws2_32.dll","str","inet_ntoa", "uint",$DecIP) If @error Then Return SetError(1,"0.0.0.0") Return $IPString[0] EndFunc $returnedText = DllStructCreate("char[" & DllStructGetData($ECHORet, "DataSize") & "]", DllStructGetData($ECHORet, "Data")) MsgBox(0, 'Ping results' , "The ping was successful: " & ($pingSucess=1) & @CRLF & _ "The destination IP was: " & _DecIPToString(DllStructGetData($ECHORet, "Address")) & @CRLF & _ "The ping time was: " & DllStructGetData($ECHORet, "RoundTripTime") & " ms" & @CRLF & _ "The transmitted data (String): " & DllStructGetData($returnedText, 1)) #ce EndFunc ;==>_PingLikeMicrosoft
    1 point
×
×
  • Create New...