Jump to content
Sign in to follow this  
PionnerCast

NMap UDF (Beta Version)

Recommended Posts

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

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Mudoch
      I need to replace a desktop applications functionality. I'll call it App "A".
      The application has defined 2 hot keys one that toggles between it and another window, App "B", and one that triggers keystrokes to App "B" to get data where App "A" can access it. Then tells app "A" to fire off processing of data.. Unfortunately when App "B" is a 64bit application this functionality no longer works. 
       
      For now I've hobbled together a work a round solution by using 2 apps with what appears to be similar abilities. AutoIt and a desktop application that allows me to define the 2 hot keys. The SutoItX Dll is great for my processes within App "A" as it uses VBA for event driven tasks.
      The second app allows me to define the Hot keys and which windows they belong to.
      My fail is on how to use AutoIT to define the hot Keys and link to specific windows.
      So as I see this working:
                App "A" launches and fires off internal VBA code that in turn sets up HotKeys. If App "B" is not found code shuts down without enabling the hotkeys.  
                A hot key of CTRL-F1 toggles, activates window, back and forth between App "A and "B"  So the hotkey is captured only when either App "A" or "B" is currently the active focus. and swaps the active focus application window.
                A hot key of CTRL-F2 from App "B", Send Key strokes to App "B" to place App "B" windows' content into windows clip board then switch to App "A" and send a keystroke, CTRL-F3, to trigger processing the clip board through App "A"'s normal event handlers.  App "A" already knows that CTRL-F3 means to run custom VBA code to process the clipboard.
      Any help would be appreciated here, thanks.  
    • By PramodR
      I see couple of ways to import module ,  one with specifying absolute path of the file to get imported, by this logic i believe to import a specific module will be like #include <c:\modulepath\duplicatemodule.au3>
      but i see some registry changes also made in this link , can someone explain why that registry change is really required.
       
    • By PramodR
      I am trying to execute a exe file in auto it as elevated previlage , but not successful till now . below are the methods i tried till now.
      Disabled UAC access from windows and  selected run only as administrator from executable properties.  i logged in as administrator but still exe needs to launch as run as administrator.
       
      Used Below methods from forum still no luck. anything i missing? i tried to use powershell.ps1 intead of exe as well.
      1.  Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, $RUN_LOGON_NOPROFILE, "c:\Exec.exe", "", @SW_SHOWMAXIMIZED)
      2.  RunWait("C:\Automation\TestScripts\Writefilter.exe", @WindowsDir, @SW_MAXIMIZE)     - Std out error
       
      This command gives out put as running with admin rights
      #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #RequireAdmin Example() Func Example()     ; Change the username and password to the appropriate values for your system.     Local $sUserName = "Admin"     Local $sPassword = "PASSWORD"     Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 0, "noetpad.exe", "", @SW_SHOWMAXIMIZED)     ; Run Notepad with the window maximized. Notepad is run under the user previously specified. ;~     RunWait(@WindowsDir & "C:\automation\TestScripts\Writefilter.exe", @WindowsDir, @SW_MAXIMIZE) EndFunc   
    • By PramodR
      Hello,
      I have below code which execute well when all prerequisite met, when window pop up is not available its throwing an error. i want to capture error instead of error  out.
      error handling added in the code to capture it but it does not work still giving me error saying Variable must be of type "Object".
      $oCurWin.FindAll($treescope_subtree, $oCondition, $pElements)
      $oCurWin^ ERROR
      How to catch error properly . 
       
       
    • By PramodR
      Hello,
      I have to execute below block of code in elevated previllage, as that particular wmic class will work only with admin previlage.
      i am getting out put when i launch autoit as administrator,  but i will not be able to launch autoit as admin in this particular case but my user have admin rights.
      is there any better way i can run those command as administrator.?
      tried below steps:
      i have tried #RequireAdmin but that creates a user prompt  Tried using Runas command but gives error as wrong username or password , stuck with that step.  
       
×
×
  • Create New...