PionnerCast

NMap UDF (Beta Version)

3 posts in this topic

#1 ·  Posted (edited)

later , I will add more functions , please note that the main requirement is to have Nmap already installed in your machine

; ******Nmap UDF! v1.0.1*******
;Added and created by Pionner
;Chilean-Brazilian Developer
;Notice that you've nmap already installed in your machine
;In this case I dont add preventers or even error handlers, such as network connection fail or detect if nmap is already installed.

#include-once
#include <Array.au3>
#include <StringConstants.au3>
;#include

Global Const $NMAP_RAW_OUT = 0
Global Const $NMAP_ARRAY_OUT = 1
Global Const $NMAP_FILE_TXT = 2
Global Const $NMAP_FILE_XML = 3

; #FUNCTION# ====================================================================================================================
; Name ..........: _Nmap_SingleScan
; Description ...: Performs an scan to retrieve open ports using @comspec and child process
; Syntax ........: _Nmap_SingleScan($ip_address, $output = 0 , $dir = @ScriptDir)
; Parameters ....: $ip_address - A valid IpV4 address as string.
; $output - [optional] Select how the result will be displayed. it can be...
; $NMAP_RAW_OUT [0] - raw results with all headers into a string.(default)
; $NMAP_ARRAY_OUT[1] - a simple 2D array indicating port/protocol, status and Service
; $NMAP_FILE_TXT[2] - Save the Results to .txt file into a custom folder (default @ScriptDir)
; $NMAP_FILE_XML[3] - Save the Results to .xml file into a custom folder (default @ScriptDir)
; $dir - [optional] Set The folder to save your output file
; Return values .: success: return the results as specified above
; Author ........: Pionner
; Modified ......:
; Remarks .......: take in count that It will take several seconds to accomplish without notifications
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _Nmap_SingleScan($ip_address, $output = 0 , $dir = @ScriptDir)
    Local $Raw, $ix, $pSS
    Dim $NwArOut[3][3]
    Select
        Case $Output = 2
            $fileOuput = StringReplace($ip_address, ".", "_") & ".txt"
        Case $Output = 3
            $fileOutput = StringReplace($ip_address, ".", "_") & ".xml --no-stylesheet"
        Case Else
            $fileOutput = ""
    EndSelect
    $ports = Run(@ComSpec & " /c nmap " & $ip_address & " " & $fileOutput , $dir , @SW_HIDE, $STDOUT_CHILD)
    ProcessWaitClose($ports)
    $ArOutcome = StdoutRead($ports)
    Switch $output
        Case 0
            Return $ArOutcome
        Case 1
            local $iw=0
            $Raw = StringSplit($ArOutcome,@CRLF,$STR_ENTIRESPLIT)
            For $ix = 7 to $Raw[0]-3
                $pSS = StringSplit(StringRegExpReplace($Raw[$ix],"\ +","|"), "|")
                $NwArOut[$iw][0]= $pSS[1]
                $NwArOut[$iw][1]= $pSS[2]
                $NwArOut[$iw][2]= $pSS[3]
                ReDim $NwArOut[$iw+2][3]
                $iw = $iw + 1
            Next
            Return $NwArOut
        Case Else
            Return True
    EndSwitch
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _Nmap_MultiScanByArray
; Description ...: Scan multiple ips at once retrieve an Array pack with results
; Syntax ........: _Nmap_MultiScanByArray($ip_array, $pipe)
; Parameters ....: $ip_pack - An Array/String.
; $pipe - The separator string (dafault is coma)
; $output - [optional] Select how the result will be displayed. it can be...
; $NMAP_RAW_OUT [0] - raw results with all headers into a string.(default)
; $NMAP_ARRAY_OUT[1] - complex 2D array 1st Col = Ip's 2nd to nth Col... port/protocol
; $NMAP_FILE_TXT[2] - Save the Results to .txt file into a custom folder (default @ScriptDir)
; $NMAP_FILE_XML[3] - Save the Results to .xml file into a custom folder (default @ScriptDir)
; $dir - the path to save the results
; Return values : a XML file with speciific Format into your @scriptdir directory
; Author ........: Your Name
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Nmap_MultiScanByArray($ip_pack, $pipe="|", $dir = @ScriptDir)
    Local $ipCalc = StringReplace($ip_pack,$pipe," ")
    $ports = Run(@ComSpec & " /c nmap " & $ipCalc , $dir , @SW_HIDE, $STDOUT_CHILD)
    ProcessWaitClose($ports)
    $ArOutcome = StdoutRead($ports)
    Select
        Case ""
            Return $ArOutcome
        Case 1
            $ver = StringSplit($ArOutcome,"" & @CRLF,$STR_ENTIRESPLIT)
            $lUp = _ArrayFindAll($ver,"report",0,0,0,1)
            Dim $OutArrMult[1][2]
            Dim $ips[1]
            For $ix=0 to UBound($lUp)-1
                $ips[$ix] = StringReplace($ver[$lUp[$ix]],"Nmap scan report for ","")
                Local $in = ($lUp[$ix]+4)
                Local $iCol = 1
                $OutArrMult[$ix][0] = $ips[$ix]
                ReDim $ips[UBound($ips)+1]
                While $ver[$in + $iCol] <> ""
                    $iRow = StringSplit(StringRegExpReplace($ver[$in + $iCol],"\ +","|"),"|")
                    $OutArrMult[$ix][$iCol] = $iRow[1]
                    ReDim $OutArrMult[$ix+2][UBound($OutArrMult,2)+1]
                    $iCol = $iCol + 1
                WEnd
            Next
            Return $OutArrMult
    EndSelect
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _Nmap_MultiScanByList
; Description ...: Use a .txt with a list of lots of ipv4 addresses and make it hapen!
; Syntax ........: _Nmap_MultiScanByList($file)
; Parameters ....: $file - the Full path of file that contains the ipv4 list.
; $dir - the destination fiolder
; Return values .:
; Author ........: Pionner
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Nmap_MultiScanByList($file, $dir)
    $ports = Run(@ComSpec & " /c nmap -iL " & $file , $dir , @SW_HIDE, $STDOUT_CHILD)
    ProcessWaitClose($ports)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _Nmap_ScanByRange
; Description ...:
; Syntax ........: _Nmap_ScanByRange($ip, $range)
; Parameters ....: $ip - An integer value.
; $range - An unknown value.
; Return values .: None
; Author ........: Your Name
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Nmap_ScanByRange($ip, $range)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _Nmap_ScanEntireSubnet
; Description ...:
; Syntax ........: _Nmap_ScanEntireSubnet($ip_loc)
; Parameters ....:
; Return values .: None
; Author ........: Your Name
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Nmap_ScanEntireSubnet($ip_loc)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _Nmap_ScanAgressiveMode
; Description ...: Make a Agressive Scan to a Ip address (no stealth mode)
; Syntax ........: _Nmap_ScanAgressiveMode($ip_address)
; Parameters ....: $ip_address - A Valid Ipv4 address.
; Return values .: Open ports for given IP
; Author ........: Pionner
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Nmap_ScanAgressiveMode($ip_address)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _Nmap_ScanIpv6Target
; Description ...:
; Syntax ........: _Nmap_ScanIpv6Target($ip_address)
; Parameters ....: $ip_address - A Valid Ipv6 address
; Return values .: None
; Author ........: Your Name
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Nmap_ScanIpv6Target($ip_address)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _Nmap_ARPPing
; Description ...: Ping a host with ARP script
; Syntax ........: _Nmap_ARPPing($ip_address)
; Parameters ....: $ip_address - A valid Ipv4 address.
; Return values .: Open Ports of given
; Author ........: Your Name
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Nmap_ARPPing($ip_address)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _Nmap_ScanFastMode
; Description ...: Scan the given Ipv4 address in Turbo mode with minimal verbosing info
; Syntax ........: _Nmap_ScanFastMode($ip_address)
; Parameters ....: $ip_address - An integer value.
; Return values .: None
; Author ........: Your Name
; Modified ......:
; Remarks .......:
; Related .......:
; Example .......: No
; ===============================================================================================================================
Func _Nmap_ScanFastMode($ip_address)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _Nmap_ExecuteNSEscript
; Description ...:
; Syntax ........: _Nmap_ExecuteNSEscript($ip_address, $sname[, $sarguments = ""[, $fileoutput = ""]])
; Parameters ....: $ip_address - An integer value.
; $sname - A string value.
; $sarguments - [optional] A string value. Default is "".
; $fileoutput - [optional] A boolean value. Default is "".
; Return values .: None
; Author ........: Your Name
; Modified ......:
; Remarks .......:list of interesting nse scripts
; nmap -sU -p 161 -T4 -d -v -n -Pn --script snmp-interfaces & ip -- get the remote MAC address
; nmap -sU -script=nbstat.nse -p137 --open 172.192.10.0/23 -oX 172.192.10.0.xml | grep MAC * | awk -F";" {'print $4'}
; Related .......: ; Link ..........:
; Example .......: Yes
;
; ===============================================================================================================================
Func _Nmap_ExecuteNSEscript($ip_address, $sname,$sarguments = "", $fileoutput= "")
EndFunc

 

Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

PionnerCast,

When you post code please use Code tags - see here how to do it - so that it is contained in a scrolling box with syntax colouring.

M23

Edit: A few spare minutes - so I did it for you.

Edited by Melba23
1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Welcome @PionnerCast.  Neat idea to create an AutoIt wrapper for NMAP.  I'd recommend reading the Best coding practices article.  It will provide some useful understanding and guidance.  Also, looking at your UDF so far, it looks like there will be a lot of room for optimization.  I recently helped (try) to explain the concept of coding modular-ly.  You might benefit from that as well.  It may give you a general idea on on way you could consolidate your UDF.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • GTAVLover
      By GTAVLover
      I recently tried to use ControlClick method to send a mouse click command to a button in a application, but I noticed that it is not working when I give first parameter as a window handle (HWND). But, when I give class name or window title, it works fine. I used AutoItX3 and VBScript. 
      Following are the commands I tried in VBScript:
      Dim WINAPI: Set WINAPI = WScript.CreateObject("WinAPIWrapper.WINAPI") Dim AutoItX3: Set AutoItX3 = WScript.CreateObject("AutoItX3.Control") Dim WindowHandle: WindowHandle = WINAPI.WinAPI_FindWindow("my window title", "my window class") 'Window handle obtains fine by my wrapper function 'Above window handle is obtained as a hexadecimal string. (I.E. - 0x00000000) I tried it like: WScript.Echo CStr(AutoItX3.ControlClick(WindowHandle, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(CLng("&h" + Replace(WindowHandle, "0x", "")), "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(000000, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(0x00000000, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK Only following commands work: WScript.Echo CStr(AutoItX3.ControlClick("[CLASS:my window class]", "", "[CLASS:Button; INSTANCE:1]")) // WORKS FINE WScript.Echo CStr(AutoItX3.ControlClick("My window title", "", "[CLASS:Button; INSTANCE:1]")) // WORKS FINE  
      If any of your suggestions don't work, I will have to write a wrapper function myself to send mouse click commands. I chosen AutoIt V3 because it is good specially when comes to send keystrokes to applications. Please tell me why this won't work when I give window handle as first parameter.
      Thanks in advance.
    • Yash91
      By Yash91
      Hi Experts,
      I want to integrate AutoIT with Eclipse to write my code in java for automating the desktop base application, i have integrate jacob 1.18 and verify the dll's also but i am getting How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version 51 issue.
      I am using 32 bit windows xp with java 1.6 version.
      Java 1.7 is unsupported in 32 bit windows xp. is there any solution for the same.
    • YashShrivastava
      By YashShrivastava
      Hi Experts,
      I am getting error: _ExcelBookOpen() undefined function in auto IT scite whenever i execute any program using functions.
      i defined the functions name also but this error is not getting resolved.
      _ExcelBookOpen(): undefined function
      _ExcelReadCell():undefined function
      require your inputs to fix this issue. I'm going through the forums and examples, but can't find anything and follow the suggestions but this issue hasn't got resolved.
       
    • srini
      By srini
      I am trying to automate the windows GUI application, in the main window of this application i have one gridview control in it, and when you click on the any row of the gridview separate windows will be opened based on the selection of the row. 
      we have our existing framework implemented using the core java,  i have used AutoITX4java.jar file to automate the above application. and controlCommandListView options used to click on grid view row item. nothing is working. 
      my question is AutoIT can be used/called directly from java file??? instead of using the AutoITX4java.jar file???
      AutoIT supports GridView automation??? like gridview count and gridivew row item click event automation ect...????
      Any help would be really appricate!!
      Thanks
      Srini
      srini20483@gmail.com
       
    • Valnurat
      By Valnurat
      Hi experts.
      I'm trying to get this to work:
      https://www.autoitscript.com/forum/topic/173949-using-the-autoit-powershell-cmdlets/
      but I get an error:  error: syntax error (illegal character)

      "Import-Module .\"
      Can anyone help me?