Sign in to follow this  
Followers 0
JLevitt

Text recognition?

7 posts in this topic

Hello guys I was wondering if there is a way to make a script recognize text somehow. Basically what I'm trying to do is have a script recognize text in a DOS prompt table and record it. For example: When you type arp -a in DOS you will get a table showing everyone who has pinged you. I'd like to automatically record those IP address entries in the table and drop them in a text file. I know very well how to do everything except recognize those areas since they can't exactly be selected to copy and paste unfortunately. Any help would be greatly appreciated. Thanks in advance.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to the forum!

If you run a search on "OCR" or "Text recognition" you'll find a lot of related topics.

This might be a good one to start with: Tesseract (Screen OCR) UDF

Edit: I guess I answered your OCR question, but... could you not just pipe the output of the arp command directly into a text file with something like "arp -a > arp.log" (which would create a file named arp.log)? You could then easily remove any unwanted text from that file.

Edited by Spiff59

Share this post


Link to post
Share on other sites

I'm actually going to email it to myself if I can get it to work, but I'd rather not post the whole script. I'm obviously fairly new to this, but this is a very, very basic little piece of what I have.

Global $Paused

HotKeySet("{HOME}", "TogglePause")

HotKeySet("{END}", "Terminate")

While 1

Sleep(2000)

Send("{LWINDOWN}")

Sleep(10)

Send("r")

Sleep(10)

Send("{LWINUP}"); access run box

Sleep(500)

Send("cmd")

Sleep(10)

Send("{ENTER}"); access command prompt

Sleep(500)

Send("cd/");move to root

Send("{ENTER}")

Sleep(10)

Send("arp")

Send("{SPACE}")

Send("{-}")

Send("a");no idea hot to copy entries since they aren't able to be selected

Send("{ENTER}")

Sleep(50)

Send("PingedBy.txt")

Send("{ENTER}"); I'd typically paste with ^v... but I can't copy so I don't know what I'd have to do here

Sleep(500)

Send("{ALT}");access menu

Sleep(100)

Send("f"); file option

Sleep(100)

Send("x"); Exit Notepad

Sleep(1000)

Send("exit"); types exit in command prompt

Sleep(10)

Send("{END}")

WEnd

Func TogglePause()

$Paused = NOT $Paused

While $Paused

sleep(100)

ToolTip('"Paused"',0,0)

WEnd

ToolTip("")

EndFunc

Func Terminate()

Exit 0

EndFunc

Share this post


Link to post
Share on other sites

Pipe it to a log. OMG why didn't I think of that. I feel so retarded. That's brilliant. Thank you very much.

Share this post


Link to post
Share on other sites

You could also use Run(@Comspec....... and read the StdIO stream. If there is a certain portion that you want, for example just the IP, you can parse it out of the result.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

The stdio route mentioned above would avoid any text file or disk activity, but I'd already thrown together something for you to play with using piping that might get you started:

#include <Array.au3> ; needed for _ArrayDelete and _ArrayDisplay
#include <File.au3> ; needed for _FileListToArray
#include <Process.au3> ; needed for _RunDOS
Global $aLogFile ; array variable for _FileListToArray needs to be predefind
Global $Logfile = "C:\arp.log"

_RunDOS ("arp.exe -a > " & $Logfile) ; run arp and pipe output into text file
_FileReadToArray($Logfile, $aLogFile) ; read text file into an array

$iLogFile_index = 1 ; variable used to keep in sync with current record of array after deletions have been made
For $x = 1 to $aLogFile[0] ; loop through array
    If $aLogFile[$iLogFile_index] = "" Then ; delete blank lines
        _ArrayDelete($aLogFile, $iLogFile_index)
        $aLogFile[0] -= 1 ; decrement value of first array elements to reflect new array size
    Else
        $aLogFile[$iLogFile_index] = StringStripWS($aLogFile[$iLogFile_index], 1) ; trim leading spaces from array element
        $iLogFile_index += 1 ; no deletion was made during this interation loop, so increment index
    EndIf
Next

_ArrayDisplay($aLogFile)

You'd might next want to insert a test to throw away array entries that don't begine with a numeric (IsNumeric, StringLeft, _ArrayDelete). Possible split up your remaing lines containing IP addresses (StringSplit, or maybe StringInStr and StringLeft), and so on...

PS - The tricky stuff regarding the $iLogFile_index variable is necessary because, for instance, say you're looping through your array that has 10 elements and looking at element 5, and you delete that element, _ArrayDelete shifts all the remaining elements down a slot so as not to leave "holes" in your array. So, what was originally element 6, has become the new element 5, and the $iLogFIle_index variable ensures that the next pass of the loop (when $x would equal 6) will look at element 5 which has not yet been processed. I hope I explained that not too badly. lol

Edited by Spiff59

Share this post


Link to post
Share on other sites

Wow man. This is a bit above my level, but I'm going to play with it til I figure it out. Thank you very much.

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  
Followers 0