juicyjon Posted May 15, 2012 Posted May 15, 2012 I am trying to make a script that will look at an nmap scan output called results then check a list of IPs. After it checks it i want it to remove any IPs that responded as up from the list then delete the results text file so the nmap scan can make a new one. This is the script i have so far any suggestions?fwautoscan.au3 The Juiciest Of The Jons
juicyjon Posted May 15, 2012 Author Posted May 15, 2012 #include <IE.au3> #include <String.au3> #include <Array.au3> #Include <File.au3> $file = FileOpen ("E:documentsfwiplist1.txt",2) $file1 = FileOpen ("E:documentsresults.txt",0) $file1 = FileRead ($file1) $fileread = Fileread ($file) $x = _FileCountLines ("E:documentsfwiplist1.txt") ; If FileRead ($file) = FileRead ($file1) Then ; MsgBox (0,"","Files are the Same.") ; Else ; MsgBox (0,"","Files are Different.") ; EndIf $i = 1 $j = 1 Do $line = FileReadLine($file1, $i) $line1 = FileReadLine $result = StringInStr ($file, $line) if $result > 0 Then FileWrite($file2, $line & @CRLF) EndIf $i = $i + 1 until $i = $x FileClose($file) FileClose($file1) FileDelete ($file1) The Juiciest Of The Jons
Spiff59 Posted May 15, 2012 Posted May 15, 2012 (edited) You're mixing/overlapping some of your variables and variable types. A lot of people will put a one-letter lower-case prefix at the front of a variable to help keep track of what it contains. Were you adhering to that rule then you might have the following 2 lines in your script: $hFile1 = FileOpen ("E:documentsresults.txt",0) ; a file handle returned by FileOpen() $sFile1 = FileRead ($hFile1) ; a string value returned by FileRead() You might also find _FileReadToArray() of interest. Edited May 15, 2012 by Spiff59
juicyjon Posted May 22, 2012 Author Posted May 22, 2012 (edited) i think i got it now. Turns out that nmap will not work with what i am doing so i created a batch that will ping hosts and come back the the IP is either alive or dead. So now i am using this script to edit the results. Any suggestion that may make it better? Also the message boxes will be commented out after it works perfectly, and i see you can put the code into the small boxes....not sure on how to do that if you guys could let me know id be great full. Thanks. #include <IE.au3> #include <String.au3> #include <Array.au3> #Include <File.au3> DIM $string ;*************************************************************************************************************** ;Opens fwiplist.txt, results.txt and results1.txt, but results1.txt is in overwrite. $file = FileOpen ("C:fwiplist.txt",0) $file1 = FileOpen ("C:results.txt",0) $file2 = FileOpen ("C:results1.txt",2) $filey = FileRead ($file1) ;*************************************************************************************************************** ;MsgBox (0,"line",$filey) ;$filex = Fileread ($file) ;MsgBox (0,"line",$filex) ;*************************************************************************************************************** ;counts the number of lines in fwiplist.txt $x = _FileCountLines ("C:fwiplist.txt") ;*************************************************************************************************************** ;MsgBox (0,"line",$x) ;$y = _FileCountLines ("C:Documents and SettingsbreaMy DocumentsFW-Check-Scriptresults.txt") ;MsgBox (0,"line",$y) ;$filey = StringReplace ($filey, "Nmap scan report for ", "") ;$filey = StringReplace ($filey, "Host is up (", "") ;$filey = StringReplace ($filey, "# Nmap 5.51 scan initiated", "") ;$filey = StringReplace ($filey, "# Nmap done at", "") ;$filey = StringReplace ($filey, "IP addresses (", "") ;$filey = StringReplace ($filey, "2012 as: nmap -iL E:documentsfwiplist1.txt -sn -oN E:documentsresults.txt", "") ;$filey = StringReplace ($filey, "hosts up) scanned in", "") ;$filey = StringReplace ($filey, "seconds", "") ;$filey = StringReplace ($filey, "s latency).", "") $array1 = StringSplit($filey, @CRLF) $i = 1 $h = 1 ;*************************************************************************************************************** ; Do loop which will read every line of results.txt and then compare it to the fwiplist.txt, then it will search the array for ;the line it read i.e. 8.8.8.8, if there it will then write it to results1.txt untill the end of results.txt. ;*************************************************************************************************************** Do MsgBox (0," H equals",$h) $line1 = FileReadLine($file1, $i) MsgBox (0,"lineread",$line) $a = 1 $line = FileReadLine($file, $h) MsgBox (0,"line",$line1) $res = StringCompare ($line, $line1) MsgBox (0,"line1",$line1) MsgBox (0,"line",$line) Msgbox(0, "Compare", $res) $search = _ArraySearch ($array1, $line) Msgbox(0, "array search result", $search) If $search > 0 Then $a = 2 EndIf Msgbox(0, "A", $a) If $a = 1 Then $string = $string & $line & @CRLF EndIf $h = $h + 1 MsgBox (0," I equals",$i) $i = $i + 1 until $i = $x+1 Msgbox(0 , "Results", $string) ;*************************************************************************************************************** FileWrite($file2, $string) ;*************************************************************************************************************** ;Closes all files that it opened. FileClose($file) FileClose($file1) FileClose($file2) ;*************************************************************************************************************** ;copies results.txt to fwiplist.txt. FileCopy("C:results.txt", "C:fwiplist.txt", 1) ;*************************************************************************************************************** ; Only include this line once you know it gives you the results you want as it will copy results1.txt over your existing fwiplist1.txt ; I tested it using other filenames with just a few IP's in the filenames and it resulted in a results1.txt file without the IP's listed ; in results.txt ; ;FileCopy("E:documentsresults1.txt", "E:documentsfwiplist1.txt", 1) ;*************************************************************************************************************** Edited May 22, 2012 by juicyjon The Juiciest Of The Jons
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now