Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/11/2015 in all areas

  1. I needed a way to get SRV records for domains, and the closest I found was >this thread, but no, it was not as easy to 'upgrade' as trancexx said! A summary of my changes: Replaced MX specifics with SRV specifics (obviously...) Adapted the code to work with _ArraySort() instead of her custom SortArray (seemed easier than adding the extra logic I needed) Replaced the non-working RegRead with a DllCall to GetNetworkParams (not sure if that key moved or if it never was there to begin with) Added Googles dns servers to list of public ones and simplified list code Fixed a bug in ExtractSRVServerData() that garbled data if more than 1 record was received Enjoy! #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs Originally was a script to get MX records written by trancexx http://www.autoitscript.com/forum/topic/78465-mx-records-for-a-specific-domain/ Now modified to get SRV records by AdmiralAlkex #ce Opt("MustDeclareVars", 1) #include <StringConstants.au3> #include <Array.au3> Local $domain = "_sip._udp.siplogin.de" ; change it to domain of your interest Local $mx = SRVRecords($domain) If IsArray($mx) Then Local $au For $j = 0 To UBound($mx) - 1 $au &= "Priority:" & $mx[$j][0] & " Weight:" & $mx[$j][1] & " Port:" & $mx[$j][2] & " Target:" & $mx[$j][3] & @CRLF Next MsgBox(0, "SRV records for " & $domain, $au) Else MsgBox(0, "SRV records for " & $domain, "No Records") EndIf Func SRVRecords($domain) Local $binary_data = SRVQueryServer($domain) If $binary_data = -1 Then Return -1 Local $output = ExtractSRVServerData($binary_data) _ArraySort($output, 0, 0, 0, 0) Local $iStart = -1 For $iX = 1 To UBound($output) - 1 If $output[$iX][0] = $output[$iX - 1][0] And $iStart = -1 Then $iStart = $iX - 1 ElseIf $output[$iX][0] <> $output[$iX - 1][0] And $iStart <> -1 Then _ArraySort($output, 1, $iStart, $iX - 1, 1) $iStart = -1 EndIf Next If $iStart <> -1 Then _ArraySort($output, 1, $iStart, $iX - 1, 1) EndIf Return $output EndFunc ;==>SRVRecords Func SRVQueryServer($domain) Local $domain_array $domain_array = StringSplit($domain, ".", 1) Local $binarydom For $el = 1 To $domain_array[0] $binarydom &= Hex(BinaryLen($domain_array[$el]), 2) & StringTrimLeft(StringToBinary($domain_array[$el]), 2) Next $binarydom &= "00" ; for example, 'gmail.com' will be '05676D61696C03636F6D00' and 'autoit.com' will be '066175746F697403636F6D00' Local $identifier = Hex(Random(0, 1000, 1), 2) ; random hex number serving as a handle for the data that will be received Local $server_bin = "0x00" & $identifier & "01000001000000000000" & $binarydom & "00210001" ; this is our query Local $num_time, $data Local $asQueryServers = _GetDnsServerAddress() Local $asPublicServers = StringSplit("8.8.8.8|8.8.4.4|4.2.2.1|67.138.54.100|208.67.222.222|4.2.2.2|4.2.2.3|208.67.220.220|4.2.2.4|4.2.2.5|4.2.2.6", "|", $STR_NOCOUNT) Local $iSize = _ArrayConcatenate($asQueryServers, $asPublicServers) For $num_time = 0 To $iSize - 1 ; this kind of server is not what we want If StringLeft($asQueryServers[$num_time], 3) = "192" Then ContinueLoop If $asQueryServers[$num_time] = "" Then ContinueLoop UDPStartup() Local $sock $sock = UDPOpen($asQueryServers[$num_time], 53) If $sock = -1 Then ; ok, that happens UDPCloseSocket($sock) UDPShutdown() ContinueLoop ; change server and try again EndIf UDPSend($sock, $server_bin) ; sending query Local $tik = 0 Do $data = UDPRecv($sock, 512) $tik += 1 Sleep(100) Until $data <> "" Or $tik = 8 ; waiting reasonable time for the response UDPShutdown() ; stopping service If $data <> "" And StringRight(BinaryMid($data, 2, 1), 2) = $identifier Then Return $data ; if there is data for us, return EndIf Next Return -1 EndFunc ;==>SRVQueryServer Func ExtractSRVServerData($binary_data) Local $num_answ = Dec(StringMid($binary_data, 15, 4)) ; representing number of answers provided by the server Local $arr = StringSplit($binary_data, "C00C00210001", 1) ; splitting input; "C00C000F0001" - translated to human: "this is the answer for your MX query" If $num_answ <> $arr[0] - 1 Or $num_answ = 0 Then Return -1 ; dealing with possible options Local $iPriority[$arr[0]] Local $iWeight[$arr[0]] Local $iPort[$arr[0]] Local $sTarget[$arr[0]] ; server name(s) Local $output[$arr[0] - 1][4] ; this goes out containing both server names and coresponding priority/weight and port numbers Local $offset = 14 ; initial offset For $i = 2 To $arr[0] $arr[$i] = "0x" & $arr[$i] ; well, it is binary data $iPriority[$i - 1] = Dec(StringRight(BinaryMid($arr[$i], 7, 2), 4)) $iWeight[$i - 1] = Dec(StringRight(BinaryMid($arr[$i], 9, 2), 4)) $iPort[$i - 1] = Dec(StringRight(BinaryMid($arr[$i], 11, 2), 4)) $offset += BinaryLen($arr[$i - 1]) + 6 ; adding lenght of every past part plus lenght of that "C00C000F0001" used for splitting Local $array = ReadBinary($binary_data, $offset) ; extraction of server names starts here While $array[1] = 192 ; dealing with special case $array = ReadBinary($binary_data, $array[6] + 2) WEnd $sTarget[$i - 1] &= $array[2] & "." While $array[3] <> 0 ; the end will obviously be at $array[3] = 0 If $array[3] = 192 Then $array = ReadBinary($array[0], $array[4] + 2) If $array[3] = 0 Then $sTarget[$i - 1] &= $array[2] ExitLoop Else $sTarget[$i - 1] &= $array[2] & "." EndIf Else $array = ReadBinary($array[0], $array[5]) If $array[3] = 0 Then $sTarget[$i - 1] &= $array[2] ExitLoop Else $sTarget[$i - 1] &= $array[2] & "." EndIf EndIf WEnd $output[$i - 2][0] = $iPriority[$i - 1] $output[$i - 2][1] = $iWeight[$i - 1] $output[$i - 2][2] = $iPort[$i - 1] $output[$i - 2][3] = $sTarget[$i - 1] Next Return $output ; two-dimensional array EndFunc ;==>ExtractSRVServerData Func ReadBinary($binary_data, $offset) Local $len = Dec(StringRight(BinaryMid($binary_data, $offset - 1, 1), 2)) Local $data_bin = BinaryMid($binary_data, $offset, $len) Local $checker = Dec(StringRight(BinaryMid($data_bin, 1, 1), 2)) Local $data = BinaryToString($data_bin) Local $triger = Dec(StringRight(BinaryMid($binary_data, $offset + $len, 1), 2)) Local $new_offset = Dec(StringRight(BinaryMid($binary_data, $offset + $len + 1, 1), 2)) Local $another_offset = $offset + $len + 1 Local $array[7] = [$binary_data, $len, $data, $triger, $new_offset, $another_offset, $checker] ; bit of this and bit of that Return $array EndFunc ;==>ReadBinary ;Based on Authenticity code from http://www.autoitscript.com/forum/topic/119734-tcpiptoname-extremly-slow-if-no-ptr-record-exists/?p=832148 Func _GetDnsServerAddress() Local $aResult, $tBuf, $tDnsServersList $aResult = DllCall("iphlpapi.dll", "uint", "GetNetworkParams", "int*", 0, "uint*", 4) If $aResult[0] = 111 Then $tBuf = DllStructCreate("byte[" & $aResult[2] & "]") $aResult = DllCall("iphlpapi.dll", "uint", "GetNetworkParams", "struct*", $tBuf, "uint*", $aResult[2]) If $aResult[0] <> 0 Then Return SetError($aResult[0], 0, "") Local $tagIP_ADDR_STRING = "ptr Next;char IpAddress[16];char IpMask[16];uint Context;" $tDnsServersList = DllStructCreate($tagIP_ADDR_STRING, DllStructGetPtr($tBuf) + 268) Local $sOutput = $tDnsServersList.IpAddress While $tDnsServersList.Next $tDnsServersList = DllStructCreate($tagIP_ADDR_STRING, $tDnsServersList.Next) $sOutput &= "|" & $tDnsServersList.IpAddress WEnd Return StringSplit($sOutput, "|", $STR_NOCOUNT) Else Return SetError(-1, 0, "") EndIf EndFunc ;==>_GetDnsServerAddress
    1 point
  2. Now replaced by a new version of the UDF in this link. <hr> [NEW VERSION] - 7 Mar 16 Added: A new option for $iAdded (+ 512) allows you to select just one cell of the ListView rather than the whole row. A new function _GUIListViewEx_SetDefColours allows the user to set the default colours when using either or both the "colour" and "single cell selection" options. Another new function _GUIListViewEx_BlockReDraw which prevents ListView redrawing during looped Insert/Delete/Change calls - this greatly speeds up execution by avoiding lengthy redrawing when using either or both the "colour" and "single cell selection" options, use of which forces the redraw to use a WM_NOTIFY handler within the script. Changed: A number of minor internal changes to speed up the loading of the ListView when using either or both of the "colour" and "single cell selection" options. A slightly modified Example_6 script shows the new functions in use. The LH native ListView can have rows and columns added/removed using both the old and new functions and has a context menu to allow for colour selection. The contents of this ListView can be mirrored to the RH UDF-created ListView which has "single cell selection" enabled and allows the colours of any item (including the selected cell) to be changed programmatically. New UDF in the zip below. Previous changes: ChangeLog.txt Hi, It seemed that I wanted to add, delete, edit or move items in a ListView quite often in my scripts and I got fed up with having to rewrite the code to do it each time. I also wanted to be able to drag items within and between ListViews with the mouse, plus edit the items. So I decided to write a UDF to make life easier and here is the result - GUIListViewEx. If you are interested in how it works, then read this bit - if not, then skip over it: The UDF is pretty easy to use: - You start by creating a ListView (either native or UDF) and passing the returned ControlID/handle and the array you used to fill it to the _Init function of the UDF. You also indicate whether the array has a count in the [0] (or [0][0]) element and if you create an empty ListView, the UDF will still cope and will shadow any items that you insert later. If you have a ListView filled with data but no matching array, there is a function to read that data into an array for you. You can select a colour for the insert mark when dragging items if you are going to use this feature - the default is black - and decide whether to have a shadow of the dragged item follow the mouse. Finally you can set the ListView to be sortable, editable - with various options to determine how the editing process works, determine external drag/drop behaviour and whether user colours are used. - You need to register a few Windows messages, but this is a single call to the _MsgRegister function. If you already have handlers for the relevant messages, there are functions to call within these handlers instead. If you do not want to drag, then you only need the WM_NOTIFY handler loaded. - Then you just need to call the main _Insert($vData), _Delete, _Up, and _Down functions when the appropriate button is pressed, select and drag items, or use one of the edit functions and your ListView responds automatically. - The UDF shadows the contents of the ListView (as explained in the spoiler section above) so you can get its current state at any time with the _ReturnArray function . Many of the functions actually return this data after each call just to help you keep track and there are dedicated Save/Load functions. - If enabled, the user can colour individual items within the ListView - and can set certain elements to be coloured on loading if required. - There are a couple of functions that you need to run in your idle loop if you need the functionality - they detect when items are dragged and edited. - When you have finished with the ListView, you should use the _Close function to clear the memory used by the UDF to shadow its contents. It is not vital, but if you use a lot of ListViews and do not do this, you could end up running out of memory. - You can have as many ListViews as you wish on display at any one time and the same "Insert", "Delete", "Up" and "Down" buttons can be used for them all - you just have to click on the one you want to be active. The UDF also allows you to set the active ListView programatically (_SetActive) - and to determine which is currently active (_GetActive). There are also additional Insert/DeleteSpec functions which allow you to action non-active ListViews. There are 6 example scripts to show the UDF working on native and UDF created ListViews, with single or multiple columns and either filled or empty, along with the UDF itself in this zip file: Credit to martin (for the basic drag code which I found on the forum), the Array UDF authors (for the basis of the array functions) and LarsJ (for the basic colour handler code). Happy for any feedback - hopefully positive! M23
    1 point
  3. Hi everyone, I've created a GUI that hides at the top of the screen, peeks out when mouse is held at top of screen for over ~1 second and can be clicked to slide down to display the GUI contents. Then it can be clicked again to slide away and hide after a timeout (~2.5 seconds). UPDATE 14/03/2015: Script has been completely overhauled and updated. Hope to get some feedback and perhaps improvements. Now also works in both Aero and non-Aero environments. Please make sure you download the two attached PNG files (NOT THEIR THUMBNAILS) to experience the GUI in whole glory (if you have Aero enabled). Feedback appreciated . Please do excuse me if something is not scripted in the best way possible, I am learning new things ever day and improving my autoit skills continuously. #include-once #NoTrayIcon #AutoIt3Wrapper_Outfile=Example.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_UseX64=n #include <GDIPlus.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> #include <WinAPIEx.au3> Global $bAero, $hidden = False, $tuck = False, $tucked = False, $untucked = False, $tucking = False, $untucking = False, $timer = 0, $tdiff = 0, _ $LAYERED_GUI = $WS_EX_LAYERED, $hGUI_child, $hGUI_height = 683 Global Const $hDwmApiDll = DllOpen("dwmapi.dll"), $sChkAero = DllStructCreate("int;") DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($sChkAero)) $bAero = DllStructGetData($sChkAero, 1) If Not $bAero Then $LAYERED_GUI = 0 $hGUI_height = $hGUI_height - 20 EndIf $hGUI = GUICreate("", 715, $hGUI_height, -1, 0, $WS_POPUP, $LAYERED_GUI + $WS_EX_TOPMOST, WinGetHandle(AutoItWinGetTitle())) $hIcon = _WinAPI_GetClassLongEx($hGUI, $GCL_HICON) _WinAPI_DestroyIcon($hIcon) _WinAPI_SetClassLongEx($hGUI, $GCL_HICON, 0) _WinAPI_SetClassLongEx($hGUI, $GCL_HICONSM, 0) If $bAero Then $hGUI_child = GUICreate("", 715-39, 683 - 26, 22, 3, $WS_POPUP, $WS_EX_MDICHILD + $WS_EX_TOPMOST, $hGUI) $hGUI_Font = $hGUI_child Else $hGUI_Font = $hGUI $hGUI_child = $hGUI EndIf GUISetBkColor(0xFFFFFF) GUISetFont(18, 100, Default, 'Segoe UI', $hGUI_Font, 5) GUICtrlCreateLabel('Example lbl:', 10, 25) GUICtrlCreateInput('input', 150, 20, 100, 35) $testbutton = GUICtrlCreateButton('Example button', 100, 250) GUISetFont(12, 100, Default, 'Segoe UI', $hGUI_Font, 5) GUICtrlCreateLabel('Right click on GUI to exit', 100, 500) $hGUI_child2 = GUICreate("", 112, 50, 299, 645, $WS_POPUP, $LAYERED_GUI + $WS_EX_MDICHILD + $WS_EX_TOPMOST, $hGUI_child) If Not $bAero Then GUISetBkColor(0xE0F2F7) $hGUI_Font = $hGUI_child2 GUISetFont(33, 100, Default, 'Segoe UI', $hGUI_Font, 5) GUICtrlCreateLabel(" = ", 0, 0, 112, 50, $SS_CENTER + $SS_CENTERIMAGE) EndIf GUISetCursor(0, 1, $hGUI_child2) If $bAero Then _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\panel.png') SetBitmap($hGUI, $hImage) $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\roundbn.png') SetBitmap($hGUI_child2, $hImage) _GDIPlus_Shutdown() EndIf GUISetState(@SW_SHOW, $hGUI) If $bAero Then GUISetState(@SW_SHOW, $hGUI_child) GUISetState(@SW_SHOW, $hGUI_child2) While 1 $mPos = MouseGetPos() If BitAnd($hidden, $mPos[1] = 0, $timer = 0) Then $timer = TimerInit() Sleep(10) ElseIf $mPos[1] <> 0 Then $timer = 0 $tdiff = 0 EndIf If $timer <> 0 Then $tdiff = TimerDiff($timer) If BitAND($hidden, Not $tucked, $mPos[1] <> 0, Not $tucking) Then $tuck = True $untucking = False $tucking = True AdlibRegister("TuckAway", 2500) ElseIf BitAND($hidden, $tucked, $mPos[1] = 0, Not $untucking, $tdiff > 450) Then $tuck = False $tucking = False $untucking = True AdlibRegister("TuckAway") ElseIf BitAND($hidden, Not $tucked, $mPos[1] = 0, $tucking) Then AdlibUnRegister("TuckAway") $tuck = False $tucking = False EndIf $msg = GUIGetMsg(1) Switch $msg[1] Case $hGUI Switch $msg[0] Case $GUI_EVENT_CLOSE, $GUI_EVENT_SECONDARYUP Exit Case $testbutton MsgBox(0,'Button','You clicked a button!', 0, $hGUI) EndSwitch Case $hGUI_child Switch $msg[0] Case $GUI_EVENT_CLOSE, $GUI_EVENT_SECONDARYUP Exit Case $testbutton MsgBox(0,'Button','You clicked a button!', 0, $hGUI_child) EndSwitch Case $hGUI_child2 Switch $msg[0] Case $GUI_EVENT_PRIMARYDOWN If Not $hidden Then HidePanel() Else HidePanel(False) EndIf EndSwitch EndSwitch WEnd Func HidePanel($hide = True) AdlibUnRegister("TuckAway") If $hide Then $tucked = False $untucked = True $hidden = True For $i = -1 to -663 Step - 1 WinMove($hGUI, "", Default, $i) Next Else $tucked = False $untucked = False $hidden = False For $i = -664 to -4 Step 1 WinMove($hGUI, "", Default, $i) Next EndIf EndFunc Func TuckAway() If $tuck Then $tucking = False $untucked = False $tucked = True For $i = 663 to 695 Step 1 WinMove($hGUI, "", Default, -$i) Sleep(10) Next Else $untucking = False $tucked = False For $i = 695 to 663 Step - 1 WinMove($hGUI, "", Default, -$i) Sleep(10) Next EndIf AdlibUnRegister("TuckAway") EndFunc Func SetBitmap($hGUI, $hImage, $iOpacity = 255) Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage)) DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage)) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", 1) _WinAPI_UpdateLayeredWindow($hGUI, $hGUI, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA) _WinAPI_ReleaseDC(0, $hScrDC) _WinAPI_SelectObject($hMemDC, $hOld) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hMemDC) EndFunc
    1 point
  4. I have 2 favorite sites : the one Melba mentioned, and this other one http://www.rexegg.com/ On both sites explanations are clear and understandable - very important condition when dealing with regex
    1 point
  5. kcvinu, I always recommend this site. But the learning curve is steep and stays that way - when mikell says "I've been a regex student for a long time " he really means it! M23
    1 point
  6. Not an alien (so thinks my wife) but I've been a regex student for a long time - and I still am, and always will be
    1 point
  7. So... #Include <Array.au3> $sentence = " If Apple = 15 Then ; this is a condition " $words = StringRegExp($sentence, "\s*(\w+)[^;]+\s(\w+);?.*", 3) _ArrayDisplay($words)
    1 point
  8. An IDE can only be build when AutoIt3 has the hooks to do debugging etc. It would be nice but honestly: This is not a complex language and it it probably isn't worth the effort it would take. Jos
    1 point
  9. '?do=embed' frameborder='0' data-embedContent>>
    1 point
  10. Aren't you reinventing the wheel?
    1 point
  11. That is like saying you farted and it could be the smell will reach some of you but probably not.
    1 point
  12. If you feel bad with regex, why don't you use the code from boththose ? It works nice - if you just add a StringStripWS $sentence = " If Apple = 15 Then " msgbox( 0 , "" , _firstlast($sentence)) Func _firstlast($string) $aString = stringsplit(StringStripWS($string, 3) , " ") return $aString[1] & @CRLF & $aString[$aString[0]] EndFunc Edit BTW in the case below all the codes on this page will fail $sentence = " If Apple = 15 Then ; this is a condition "
    1 point
  13. Hi all, Here is a one way to deal with some combobox events: #include <GuiConstants.au3> Global Const $WM_COMMAND = 0x0111 $Gui = GuiCreate("ComboBox Handler Example") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") $ComboBox = GUICtrlCreateCombo("", 20, 80) GUICtrlSetData(-1, "Some text|More text|another text") ;Just for checking the combo focus GUICtrlCreateInput("", 20, 120) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case -3 Exit EndSwitch WEnd Func WM_COMMAND($hWndGUI, $MsgID, $WParam, $LParam) If Not BitAND(WinGetState($hWndGUI), 2) Then Return $GUI_RUNDEFMSG Local $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word Local $iCode = BitShift($wParam, 16) ; Hi Word Switch $iIDFrom Case $ComboBox Switch $iCode Case 1 Local $sComboData = GUICtrlRead($iIDFrom) Local $sComboIndex = ControlCommand($hWndGUI, "", $iIDFrom, "FindString", $sComboData) PrintF("ComboBox selected: [Index = " & $sComboIndex & "], Text = " & $sComboData) Case 3 PrintF("ComboBox has focus") Case 4 PrintF("ComboBox lost focus") Case 5, 6 PrintF("ComboBox changed/updated: " & GUICtrlRead($iIDFrom)) Case 7 PrintF("ComboBox is Opened") Case 8 PrintF("ComboBox is Closed") Case Else PrintF($iCode) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func PrintF($sStr, $Line=@ScriptLineNumber) ConsoleWrite(@LF & "+======================================================" & @LF & _ "--> Script Line (" & $Line & "):" & @LF & "!" & @TAB & $sStr & @LF & _ "+======================================================") EndFunc
    1 point
  14. Melba23

    Double click for Listview

    Jewtus, My gratitude for the thought but there is no need - the thanks I get here are quite sufficient. M23
    1 point
  15. kcvinu, I edited my code to add an explanation...
    1 point
  16. There isn't. You could check if @error is set after a function call.
    1 point
  17. Mark the one which is easiest for you to underrstand.
    1 point
  18. #Include <Array.au3> $sentence2 = "If Apple = 15 Then" $words = StringRegExp($sentence2, "(?m)\W*(\w+).*?(\w+)\W*$", 1) _ArrayDisplay($words) Here is a small explanation : (?m) : multiline mode. With this mode, ^ and $ operates on each line instead of the whole string W* : any non-word character, 0 or more times (w+) : capturing group. any word character, one or more times .*? : anything, one or more times. ? takes the smallest occurence $ : end of line or end of string
    1 point
  19. The most important thing for a working solution is to define the meaning of "word". You need to define what delimits a word. Space, comma, bracket etc.
    1 point
  20. C:Users{UserName}AppDataLocalAutoIt v3SciTEau3abbrev.properties I know, you know what you want No. Maybe Lua.
    1 point
  21. No problem friend, we don't do it for the points score here, at least I don't. As we say in Dutch, "small effort, big pleasure".
    1 point
  22. DasBo

    Dig UDF for AutoIt

    As I can't post a new topic to the example scripts forum, I will post it here. It would be nice, if one of the mods could move it to the right forum. Thanks! Ok, now for the interesting part: Some days ago I needed bonjour service discovery from within an AutoIt script. I searched the forum for a suitable solution, but didn't find any that really worked (especially for multicast dns queries for custom resource record types, as needed for bonjour service discovery). Thus I wrote my own. "Unfortunately", after the function was almost finished (and after I learned almost everything about name resolution, I never wanted to know before ), I stumbled upon an even better solution for my primary problem. Well - While I don't use it myself now, I hope somebody finds this function useful anyway. It is virtually a 'dig' like application written in AutoIt. It is well documented inside the source code (at last I hope so) and if you want to learn more about name resolution or really need a _Dig() function for your next AutoIt script, feel free to use the function for whatever you want. The parameters are described in the header comment and _Dig() returns a multi line string containing a 'dig' like output, you may easily parse with AutoIt string functions. Some examples are given below the UDF source. #include-once #Include <String.au3> #Include <Date.au3> ; You may add more "<rrtype>=<value>" pairs to $sDig_rr_types, if you want, ; but keep in mind, that you also need to add a portion of parsing code ; in DecodeRData(), if you want the ressource record data to be decoded. ; If your rrtype cannot be parsed, it will be returned undecoded in a ; generic format according to RFC 3597. Global Const $sDig_rr_types="A=1 NS=2 CNAME=5 SOA=6 WKS=11 PTR=12 MX=15 TXT=16 AAAA=28 SRV=33 A6=38 ANY=255" ; You may add more "<rrclass>=<value>" pairs to $sDig_rr_classes, if you want... Global Const $sDig_rr_classes="IN=1 ANY=255" Global $bDig_amsg ; holds the complete dns answer message Global $iDig_ptr ; Pointer needed for reading the answer message Global $iDig_q_count ; QDCOUNT (No. of messages in the question section) Global $iDig_a_count ; ANCOUNT (No. of messages in the answer section) Global $iDig_au_count ; AUCOUNT (No. of messages in the authority section) Global $iDig_ar_count ; ARCOUNT (No. of messages in the aditional section) Global $sDig_output ; the dig output will be saved here... ; #FUNCTION# ==================================================================================================================== ; Name...........: _Dig ; Description ...: Queries a DNS server and returns the result in a 'dig' like format (not exactly, but near) ; to be parsed by yourself :-) ; Syntax.........: _Dig($sDig_domain[, $sDig_server = ""[, $iDig_port = 53[, $sDig_type = "A"[, $sDig_class = "IN" _ ; [, $sDig_proto = "UDP"[, $sDig_timeout = 1]]]]]]) ; Parameters ....: $sDig_domain - Domain to query ; $sDig_server - [optional] DNS server to query (default: primary DNS server set for the NIC @IPAddress1) ; $iDig_port - [optional] port to be used for the query (default: 53) ; $sDig_type - [optional] ressource record type to be queried (default: "A") ; $sDig_class - [optional] ressource record class to be queried (default: "IN") ; $sDig_proto - [optional] IP protocol to be used (default: "UDP") ; $sDig_timeout - [optional] Timeout in seconds to wait for a response (default: 1) ; Return values .: Success - a string formatted similar to a 'dig' query ; Failure - "", sets @error: ; |1 - something went wrong (sorry, no specific error messages at the moment) ; Author ........: Andreas Börner (mail@andreas-boerner.de) ; Modified.......: Andreas Börner (mail@andreas-boerner.de) ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; No ; =============================================================================================================================== Func _Dig($sDig_domain,$sDig_server=Default,$iDig_port=Default,$sDig_type=Default,$sDig_class=Default,$sDig_proto=Default,$sDig_timeout=Default) ; Check & replace 'Default' values for optional parameters if $sDig_server=Default Then $sDig_server="" if $iDig_port=Default Then $iDig_port=53 if $sDig_type=Default Then $sDig_type="A" if $sDig_class=Default Then $sDig_class="IN" if $sDig_proto=Default Then $sDig_proto="UDP" if $sDig_timeout=Default Then $sDig_timeout=1 ; the dig output will be saved here... $sDig_output="" ; if no DNS server is provided, get the primary DNS server for the @IPAddress1 network adapter if $sDig_server="" then $sDig_server=GetPrimaryDNS() $sDig_proto=StringUpper($sDig_proto) ; random hex number (2 bytes) serving as a handle for the data that will be received Local $dig_id = Hex(Random(0, 65535, 1), 4) ; set query flags (16 bit): ; ........ ........ ; 0 QR (Query/Response Flag) (0: query / 1: for response) ; 0000 Opcode (Operation Code) (0: standard query) ; 0 AA (Authoritative Answer Flag) (always 0 in a query) ; 0 TC (Truncation Flag) (always 0 in a query) ; 1 RD (Recursion Desired) (we want recursive answers, if possible) ; ; 0 RA (Recursion Available) (always 0 in a query) ; 000 Z (Zero) (Three reserved bits set to zero) ; 0000 RCode (Response Code) (always 0 in a query) ; Local $dig_flags="0100" ; in a regular query there is one question (=> QDCOUNT=1) and no answers (ANCOUNT=AUCOUNT=ARCOUNT=0) $dig_counters="0001000000000000" ; Encode the domain to standard DNS name notation Local $sDig_domain_binary=EncodeName($sDig_domain) ; Encode the ressource record type and class to their binary equivalents Local $sDig_type_binary = EncodeType($sDig_type) Local $sDig_class_binary = EncodeClass($sDig_class) ; this is the complete query: <id/handle> <query-flags> <ressource-record-counters> <rr-type> <rr-class> Local $dig_request = $dig_id & $dig_flags & $dig_counters & $sDig_domain_binary & $sDig_type_binary & $sDig_class_binary ; this is our query ; In TCP mode, an additional length information (PDU length) has to be preceeded (the length of the whole request in bytes) ; To simplify matters, this length is calculated from the string length of $dig_request, divided by two. ; (Please note, that $dig_pdulen remains empty, if UDP protocol is used) Local $dig_pdulen="" if $sDig_proto="TCP" Then $dig_pdulen=Hex(StringLen($dig_request)/2,4) ; Now the request string can be completed finally $dig_request="0x" & $dig_pdulen & $dig_request ; start TCP or UDP service & open a socket ; (Shutdown TCP/UDP service, if no socket could be opened and return an error to the caller) Local $dig_sock if $sDig_proto="TCP" Then TCPStartup() $dig_sock = TCPConnect($sDig_server, $iDig_port) If @error Then TCPShutdown() SetError(1) Return "" EndIf Else UDPStartup() $dig_sock = UDPOpen($sDig_server, $iDig_port) If @error Then UDPShutdown() SetError(1) Return "" EndIf EndIf ; measure the query time for "Query time:" output ; (ok, it's more like 'just for fun...' :-) Local $query_time=TimerInit() ; send query to the TCP or UDP socket if $sDig_proto="TCP" Then TCPSend($dig_sock, $dig_request) Else UDPSend($dig_sock, $dig_request) EndIf ; waiting for the response... Local $tik = 0 Do ; receive the response from the TCP or UDP socket if $sDig_proto="TCP" Then $bDig_amsg = TCPRecv($dig_sock, 512,1) Else $bDig_amsg = UDPRecv($dig_sock, 512,1) EndIf Sleep(100) Until $bDig_amsg <> "" Or TimerDiff($query_time)>$sDig_timeout*1000 $query_time=Round(TimerDiff($query_time)) ; Stop TCP/UDP service (not needed anymore) if $sDig_proto="TCP" Then TCPShutdown() ; While a dns response via UDP immediately starts with the Message ID, a TCP response ; is preceeded by a 2 byte PDU length (as well as the request; see above) and the ; message id follows at position 3 in the response data. As we don't need the PDU ; length for anything, we cut it from the responseand throw it away $bDig_amsg=BinaryMid($bDig_amsg,3) Else UDPShutdown() EndIf ; from here, there is no more difference in handling TCP or UDP responses ; check response & message ID... If $bDig_amsg = "" or StringMid(BinaryMid($bDig_amsg, 1, 2), 3) <> $dig_id Then ; received nothing - or something, but not our DNS response SetError(1) Return "" EndIf ; ############ Output the formatted response ############### ;########################################################### ; initialize the global message pointer $iDig_ptr=1 ; output some 'dig' like headers $sDig_output&="; <<>> DiG for AutoIt 1.0.0 (" & $sDig_proto & ") <<>> " & $sDig_domain & " @" & $sDig_server & "#" & $iDig_port & " " & $sDig_type & @LF $sDig_output&=";; Got answer:" & @LF ; read ID's, flags & counters from message header $dig_id=ReadHex2Int(2) $dig_flags=ReadHex2Int(2) $iDig_q_count=ReadHex2Int(2) $iDig_a_count=ReadHex2Int(2) $iDig_au_count=ReadHex2Int(2) $iDig_ar_count=ReadHex2Int(2) ; extract some boolean flags from $dig_flags (see query generation above for more info) $dig_flags_flags="" if BitAND($dig_flags,32768) then $dig_flags_flags&=" qr" ; QR if BitAND($dig_flags,1024) then $dig_flags_flags&=" aa" ; AA if BitAND($dig_flags,512) then $dig_flags_flags&=" tr" ; TR if BitAND($dig_flags,256) then $dig_flags_flags&=" rd" ; RD if BitAND($dig_flags,128) then $dig_flags_flags&=" ra" ; RA ; extract opcode & rcode... ; mask 15th to 12th bit for opcode and shift result to get the integer opcode $dig_flags_opcode=BitShift(BitAND($dig_flags,30720),11) ; mask 4th to 1st bit for response code (no additional shift necessary) $dig_flags_rcode=BitAND($dig_flags,15) ; output flags, ID's & counters $sDig_output&=";; ->>HEADER<<- opcode: " & $dig_flags_opcode & ", status: " & $dig_flags_rcode & ", id: " & $dig_id & @LF $sDig_output&=";; flags:" & $dig_flags_flags & "; QUERY: " & $iDig_q_count & ", ANSWER: " & $iDig_a_count & ", AUTHORITY: " & $iDig_au_count & ", ADDITIONAL: " & $iDig_ar_count & @LF ; output ressource record sections if $iDig_q_count>0 Then $sDig_output&=@LF & ";; QUESTION SECTION:" & @LF & ";" ReadResourceRecords("q") ; forward an error from ReadRessourceRecords to the caller if @error Then SetError(1) return "" EndIf EndIf if $iDig_a_count>0 Then $sDig_output&=@LF & ";; ANSWER SECTION:" & @LF ReadResourceRecords("a") ; forward an error from ReadRessourceRecords to the caller if @error Then SetError(1) return "" EndIf EndIf if $iDig_au_count>0 Then $sDig_output&=@LF & ";; AUTHORITY SECTION:" & @LF ReadResourceRecords("au") ; forward an error from ReadRessourceRecords to the caller if @error Then SetError(1) return "" EndIf EndIf if $iDig_ar_count>0 Then $sDig_output&=@LF & ";; ADDITIONAL SECTION:" & @LF ReadResourceRecords("ar") ; forward an error from ReadRessourceRecords to the caller if @error Then SetError(1) return "" EndIf EndIf $sDig_output&=@LF & ";; Query time: " & $query_time & " msec" & @LF ; Sorry - there is no reliable way to determine the origin of the received dns response ; using the AutoIt TCP / UDP functions, as TCPRecv() / UDPRecv() does not reveal the ; TCP / UDP headers to the end user and we have nothing to output on the SERVER line ; ";; SERVER: 192.168.4.254#53(192.168.4.254)" ; ok, the last two are easy... $sDig_output&=";; WHEN: " & _Now() & @LF $sDig_output&=";; MSG SIZE rcvd: " & BinaryLen($bDig_amsg) & @LF ; Done... Return $sDig_output EndFunc ;==>_Dig ; read a ressource record section from the response message Func ReadResourceRecords($section_id) Local $i,$count Local $name_dec,$type_dec,$class_dec,$ttl_dec,$rd_len,$data_dec Switch $section_id case "q" $count=$iDig_q_count case "a" $count=$iDig_a_count case "au" $count=$iDig_au_count case "ar" $count=$iDig_ar_count case Else SetError(1) return "" EndSwitch for $i=1 to $count ; every ressource record contains a name, a type and a class $name_dec=DecodeName() $type_dec=DecodeType() $class_dec=DecodeClass() ; only ANSWER, AUTHORITY & ADDITIONAL records contain a ttl and record data $ttl_dec="" $data_dec="" if $section_id<>"q" Then $ttl_dec=ReadHex2Int(4) $rd_len=ReadHex2Int(2) $iDig_ptr_end=$iDig_ptr+$rd_len $data_dec=DecodeRData($rd_len,$type_dec) EndIf $sDig_output&=$name_dec & @TAB & $ttl_dec & @TAB & $class_dec & @TAB & $type_dec & @TAB & $data_dec & @LF Next EndFunc ; encode a literal domain name to standard DNS name notation Func EncodeName($sDig_domain) Local $ret="",$i,$sDig_domain_array ; split domain name into separate labels (a label means everything in front of a dot) $sDig_domain_array = StringSplit($sDig_domain, ".") ; append every label with it's preceeded length value to the return value For $i = 1 To $sDig_domain_array[0] ; append label length (1 byte) and label (as binary) to the encoded name $ret&=Hex(BinaryLen($sDig_domain_array[$i]), 2) & StringTrimLeft(StringToBinary($sDig_domain_array[$i]), 2) Next ; add a zero length value to finish the encoded name $ret&="00" return $ret EndFunc ; decode standard DNS name notation to a literal domain name ; this is only the starter for a (possibly) recursive DecodeNameRec() run Func DecodeName() Local $ret $ret=DecodeNameRec($iDig_ptr) ; It doesn't look "right" to simply add a period, if $ret is empty ; but I taxed my brain and didn't find the solution to handle the case ; of a zero length label INSIDE the label decoding function and not as a ; special case. If somebody knows the solution (there MUST be some ; stupidly simple solution...), please let me know. :-) ; If you want to hurt your brain, simply dig for a non-existent host ; or IP - you should get a zero length label in the authority section. if $ret="" then $ret="." $iDig_ptr+=@extended return $ret EndFunc ; recursive decode DNS name notation ; DecodeNameRec() calls itself recursively if it stumbles upon a pointer to another ; label in the response message Func DecodeNameRec($offset) local $data,$data_dec="",$offset_ptr,$len Local $offset_add=0 while 1 $len=ReadHex2Int(1,$offset+$offset_add,False) ; a label is followed by a pointer or the name consists of a pointer only (0b11xxxxxx) => need to decode recursive if BitAND(192,$len)=192 then ; get the pointer offset (filter the upper two bits (pointer identifier) from the value) $offset_ptr=BitAND(ReadHex2Int(2,$offset+$offset_add,False),16383)+1 ; DecodeNameRec() is called recursive targetting the offset in the ; response message, until a label is found that DOES NOT end with a pointer ; the decoding is complete, if all recursions returned $data_dec&=DecodeNameRec($offset_ptr) ; offset the read position behind the pointer $offset_add+=2 ExitLoop ; a label is followed by a label length (i.e. no pointer) Else ; offset the read position behind the label length value $offset_add+=1 ; label length zero => the name is completly decoded => return to caller if $len=0 then ExitLoop $data=BinaryMid($bDig_amsg,$offset+$offset_add,$len) $data_dec&=_HexToString(StringMid($data,3)) & "." ; offset the read position behind the label $offset_add+=$len EndIf WEnd ; return the new offset (to DecodeName() if this is the 1st recursion level) ; (Hint: a new offset from the 2nd recursion level and below, i.e. if DecodeNameRec() returns to itself, ; is ignored, because it must not change the global read position.) SetExtended($offset_add) Return $data_dec EndFunc ; encode ressource record type from string to 16 bit hex value Func EncodeType($rr_type) Local $ret ; search the integer value according to $rr_type in $sDig_rr_types $ret=StringRegExp(" " & $sDig_rr_types & " "," " & StringUpper($rr_type) & "=([0-9]+) ",1) ; if found: return this integer value hex encoded (16 bit) if not @error then Return Hex($ret[0],4) ; if not found... Else ; ...test, if $rr_type was given as a generic rrtype according to RFC 3597 ("TYPExxx") ; and return xxx value hex encoded (16 bit) if StringLeft(StringUpper($rr_type),4)="TYPE" Then Return Hex(StringMid($rr_type,5),4) ; ...else, set @error=1 and return RR type "ANY" (255) Else SetError(1) return "00FF" EndIf EndIf EndFunc ; decode ressource record type from 16 bit hex value to string Func DecodeType($advance=True) Local $ret="" $rr_type=ReadHex2Int(2,$iDig_ptr,$advance) ; search the name according to $rr_type value in $sDig_rr_types $ret=StringRegExp(" " & $sDig_rr_types & " "," ([0-9,A-Z]+)=" & $rr_type & " ",1) ; if found: if not @error then Return $ret[0] ; if not found return unknown rrtype as "TYPExxx" according to RFC 3597 Else return "TYPE" & $rr_type EndIf EndFunc ; encode ressource record class from string to 16 bit hex value Func EncodeClass($rr_class) Local $ret ; search the integer value according to $rr_class in $sDig_rr_classes $ret=StringRegExp(" " & $sDig_rr_classes & " "," " & StringUpper($rr_class) & "=([0-9]+) ",1) ; if found: return this integer value hex encoded (16 bit) if not @error then Return Hex($ret[0],4) ; if not found... Else ; ...test, if $rr_class was given as a generic rrclass according to RFC 3597 ("CLASSxxx") ; and return xxx value hex encoded (16 bit) if StringLeft(StringUpper($rr_class),5)="CLASS" Then Return Hex(StringMid($rr_class,6),4) ; ...else, set @error=1 and return RR class "ANY" (255) Else SetError(1) return "00FF" EndIf EndIf EndFunc ; decode ressource record class from 16 bit hex value to string Func DecodeClass($advance=True) Local $ret="" $rr_class=ReadHex2Int(2,$iDig_ptr,$advance) ; search the name according to $rr_class value in $sDig_rr_classes $ret=StringRegExp(" " & $sDig_rr_classes & " "," ([0-9,A-Z]+)=" & $rr_class & " ",1) ; if found: if not @error then Return $ret[0] ; if not found return unknown rrclass as "CLASSxxx" according to RFC 3597 Else return "CLASS" & $rr_class EndIf EndFunc ; decode ressource record data types ; Currently DecodeRData() decodes only the most important ressource record types ; record types, that are unknown, are returned in a generic (undecoded) format defined ; in RFC 3597 (see below) Func DecodeRData($len,$type_dec,$advance=True) local $ret="",$i,$data ; decode known rr types Switch $type_dec ; IPv4 internet address record case "A" $ret&=ReadHex2Int(1) ; IP - 1st octet (no preceding dot) for $i=2 to 4 ; IP - 2nd to 4th octet $ret&="." & ReadHex2Int(1) Next ; IPv6 internet address record case "AAAA" ; convert binary to hex value & insert colons for $i=1 to 8 ; short IPv6 notation Pt. 1: strip up to 3 leading zeros from every group (but leave one zero untouched) $data=StringRegExpReplace(Hex(BinaryMid($bDig_amsg,$iDig_ptr,2)),"^0{1,3}","") $ret&=$data & ":" $iDig_ptr+=2 Next ; short IPv6 notation Pt. 2: replace the first occurrence ; of one or more consecutive groups of :0 with a colon ; (and trim the last colon) ; (Hint: this approach does not necessarily return the shortest possible notation, ; as it always compresses the FIRST occurrence of at least one ":0", ; even if there is a longer group somewhere else in the address.) $ret=StringTrimRight(StringRegExpReplace($ret,"(:0)+",":",1),1) ; mail exchange record case "MX" $ret&=ReadHex2Int(2) ; mx preference $ret&=" " & DecodeName() ; mx host name ; canonial name record ; name server record ; pointer record case "CNAME","NS","PTR" $ret=DecodeName() ; host name / ns name ; start of authority record case "SOA" $ret&=DecodeName() ; Primary Nameserver $ret&=" " & DecodeName() ; Admin Mailbox (first dot is equivalent to '@') $ret&=" " & ReadHex2Int(4) ; Serial Number $ret&=" " & ReadHex2Int(4) ; Refresh interval $ret&=" " & ReadHex2Int(4) ; Retry Interval $ret&=" " & ReadHex2Int(4) ; Expiration Limit $ret&=" " & ReadHex2Int(4) ; Minimum TTL ; service locator record case "SRV" $ret&=ReadHex2Int(2) ; Priority $ret&=" " & ReadHex2Int(2) ; Weight $ret&=" " & ReadHex2Int(2) ; Port $ret&=" " & DecodeName() ; host name ; text record ; sender policy framework record case "SPF","TXT" ; Althrough the RDLENGTH field already contains a 2-byte length for the TXT/SPF record (as for any other ressource record type) ; the record itself consists of zero or more strings, preceeded by a single byte length value. These strings have to be ; read one after another. $ret='' $data=BinaryMid($bDig_amsg,$iDig_ptr,$len) while BinaryLen($data)>0 $string_len=int("0x"&Hex(BinaryMid($data,1,1))) $ret&='"' & BinaryToString(BinaryMid($data,2,$string_len)) & '" ' $data=BinaryMid($data,$string_len+2) ; cut $data after $string_len bytes (plus 1 for the length byte itself) WEnd $ret=StringTrimRight($ret,1) $iDig_ptr+=$len ; all unknown ressource record data are returned in a generic (undecoded) hex format case Else $ret="\# " & $len & " " & hex(BinaryMid($bDig_amsg,$iDig_ptr,$len)) ; return rdata of unknown record types according to RFC 3597 $iDig_ptr+=$len EndSwitch Return $ret EndFunc ; read $len bytes from the response message ; if not explicitly given, read starts from the current global read position ; if not explicitly False, global read position is set behind the read data Func ReadHex2Int($len,$offset=$iDig_ptr,$advance=True) Local $ret $ret=Int("0x"&hex(BinaryMid($bDig_amsg,$offset,$len))) if $advance then $iDig_ptr+=$len return $ret EndFunc ; get primary dns server from the network adapter with @IPAddress1 from NetworkAdapterConfiguration WMI object Func GetPrimaryDNS() Local $ret ; some constants & variables needed for the WMI object Const $wbemFlagReturnImmediately = 0x10 Const $wbemFlagForwardOnly = 0x20 Local $colNICs="", $NIC, $strQuery, $objWMIService ; query the network adapter configuration to $colNICs $strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration" $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2") $colNICs = $objWMIService.ExecQuery($strQuery, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) ; search @IPAddress1 in result object / if found, set return value to the first DNSServerSearchOrder element If IsObj($colNICs) Then For $NIC In $colNICs if $NIC.IPAddress(0)==@IPAddress1 then $ret=$NIC.DNSServerSearchOrder(0) ExitLoop EndIf Next Else SetError(-1, "No WMI Objects Found for class: Win32_NetworkAdapterConfiguration", "") EndIf ; free the WMI object $objWMIService = "" $colNICs = "" $NIC = "" Return $ret EndFunc Here are some examples for usage: #include "_Dig.au3" ; simple dig for "wikipedai.org" (using the first configured dns server of your primary NIC) ConsoleWrite(_Dig("wikipedia.org") & @crlf) ; dig for "wikipedia.org", explicitly querying a 'Level 3 Communications' dns server ConsoleWrite(_Dig("wikipedia.org","4.2.2.1") & @crlf) ; do a reverse lookup for IP 4.2.2.1: ; Technically a reverse lookup query doesn't differ in any way from a standard/forward query. ; To indicate, that you want the server to return a host name for your IP and not the other way round ; you just have to provide your IP in the in-addr format: Reverse the four octets of your IP and append ; '.in-addr.arpa'. ; ; I know, the dig command line tool knows the -x option for reverse lookups - But for this _Dig() function ; you have to do all the hard work for yourself... :-) (Ok, at least you don't need to THINK for yourself ;-) $ip="4.2.2.1" $in_addr=StringRegExpReplace($ip,"([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)","\4\.\3\.\2\.\1") & ".in-addr.arpa" ConsoleWrite(_Dig($in_addr,"87.118.100.175",110) & @crlf) ; dig for "wikipedia.org", querying a 'German Privacy Foundation' dns server at the alternative port 110 ConsoleWrite(_Dig("wikipedia.org","87.118.100.175",110) & @crlf) ; dig CNAME records for "en.wikipedia.org" (using the first configured dns server of your primary NIC, Port 53) ConsoleWrite(_Dig("en.wikipedia.org",Default,Default,"CNAME") & @crlf) ; digging around in the chaosnet class ; Ok, this is some advanced and mostly theoretical example: ; You will rarely want to dig for chaosnet class records, but modern bind versions misuse the chaosnet class ; to provide some system and version information about themselves. Thus, you may dig some dns server ; for TXT records of the domain "version.bind" and it may return it's version information. But don't expect ; to much, as often this version information is garbled for security reasons (compare the output of the two ; examples below). ; ; This example also shows how to deal with custom/exotic record types & classes: As I don't wanted to include ; every possible type & class keyword, _Dig() doesn't know the record class "CH" for chaosnet and will return ; no records but an error. But according to RFC 3597 a dns query client should be able to deal with generic ; types and classes in the form "TYPE<tid>" and "CLASS<cid>". So does _Dig() and you may use 'CLASS3' as the ; class parameter to retrieve records from the Chaosnet class. ; ; There is a quite comprehensive list for record types on wikipedia: http://en.wikipedia.org/wiki/List_of_DNS_record_types ; RFC 2929 holds a list of all defined record classes: http://www.ietf.org/rfc/rfc2929.txt ConsoleWrite(_Dig("version.bind","193.176.144.2",Default,"TXT","CLASS3") & @crlf) ConsoleWrite(_Dig("version.bind","4.2.2.1",Default,"TXT","CLASS3") & @crlf) ; One more example for generic types: Instead of digging for the record type 'CNAME', you may use 'TYPE5' ; alternatively, to get the same result: ConsoleWrite(_Dig("en.wikipedia.org",Default,Default,"TYPE5") & @crlf) ; This is an example for bonjour service discovery with _Dig(), ; which is actually nothing more than a mDNS query to a multicast dns server on your local network: ConsoleWrite(_Dig("_workstation._tcp.local","224.0.0.251",5353,"ANY")) ; dig for "wikipedai.org" in TCP mode ; (please note, that not all dns servers accept dns over tcp requests; ; especially home lan routers often refuse connection to Port 53/TCP) ConsoleWrite(_Dig("wikipedia.org","4.2.2.1",Default,Default,Default,"TCP") & @crlf) ; dig for "wikipedai.org" (waiting max. 5 seconds for a reply) ConsoleWrite(_Dig("wikipedia.org",Default,Default,Default,Default,Default,5) & @crlf) Ok - Have fun!
    1 point
×
×
  • Create New...