Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing data from scroll to a file 1

Status
Not open for further replies.

malium

ISP
Jun 26, 2003
23
0
0
US
Not sure I can do this - I'm logging into a router and viewing config files that have sequences of IP addresses intermingled with other data - the IPs are not sequential.

I'd like to capture the IPs to a file of just a list of the IPs, preferably sorted though I can sort the file later if needed. Also have a similar desire to grab lists of MAC addresses to files.

To complicate the IP scenario a little - the IPs are all in a similar sequence, i.e. 10.x.x.x, but there are also redundant entries of 10.x.x.1 which I don't care to see at all, especially multiple times. Once is ok. But if other addresses are duplicated I do want them to show more than once. It would be ideal to also pair the MAC address with the IP.

i.e. I see things like:

...
client.... 0090.xxxx.xxxx
IP 10.x.x.x 255.255.0.0
.... 10.x.x.1....
----MORE-------

and page through multiple pages of this. I'd like to have a script capture a parsed list to a text file in a format like

10.x.x.2
10.x.x.4
10.x.x.3

and sort that if possible, and better yet pair it with the MAC address from previous line, such as

00xx.xxxx.xx01 10.x.x.3
00xx.xxxx.xxc2 10.x.x.49
00xx.xxxx.xxe7 10.x.x.7

and sort that by MAC address or IP in different variations of the script.

Is this possible? If so, can you offer any suggestions or examples to get me started down the right path?

Thanks in advance for any help you can offer.
 
Is the data always in the format you specified below:

client.... 0090.xxxx.xxxx
IP 10.x.x.x 255.255.0.0
.... 10.x.x.1....
----MORE-------

such that the IP address (10.x.x.x in your example) is always after a line that starts with client? Or even better, are the addresses you are interested in one a line that always starts with IP? The key will be getting the data in a structured format that a script can consistently read.


aspect@aspectscripting.com
 
thanks for the reply. Yes, it should always be consistent. The actual data is in this format, I didn't have it handy last night:

ip dhcp pool cm-0090.XXXX.XXXX
host 10.0.0.N 255.255.0.0
client-identifier 0100.90xx.xxxx.xx

where XXXX.XXXX = xx.xxxx.xx but shifted to lower case, and N = a number up to 3 digits and is not =1. Eventually the N will probably extend to the 3rd octet also, i.e. 10.0.N.N.
 
That doesn't look too bad. If you can tell me what strings you want filtered out, I can whip a script up to parse those out. From your example, I'm assuming you want:

cm-0090.XXXX.XXXX
10.0.0.N (as long as N is not 1)
0100.90xx.xxxx.xx

aspect@aspectscripting.com
 
Thanks. I'd probably need to specify what flags the end of the list - that should be the seesion returning to a prompt of

#

End result I'd like is to write a file or have a formatted display of the data in pairs, taking many variations of the strings in the format I mentioned previously into a file like:

0090.XXXX.XXXX 10.0.N.N
0090.XXXX.XXXX 10.0.N.N
0090.XXXX.XXXX 10.0.N.N

and if it can be done by the script, sorted by either column. With an example I can probably adapt one that sorts the first column to make a second script to write a second file sorted by the second column.

I'd prefer output piped to a file and overwriting any previous version of the file when this runs, or renaming the previous to a .bak file. But formatted displays of the data in procomm would be a nice partial fix if that's easier.

Any of this would help solve my problem of getting reasonable reports from the unsorted data, though if I can just get the stuff in a file in that format I can sort as needed in a spreadsheet, javascript, etcetera so the sort isn't as critical as filtering to only get the data I want.

Then the flipside of the question in my related post is how I can take a string from the windows clipboard and parse it back into the format I want and convert case so I can use the XXXX.XXXX part in uppercase text in one instance and lower case in the alernate format xx.xxxx.xx in the second instance - to write new entries in the format I used in my previous post on this thread. I'd really like to be able to post the two strings from a web page form where a user enters two fields, then have that run a telnet session w/script that inserts the strings and other data in the descired format. But a user prompt in the telnet session for the data or a script that grabs it from the windows buffer is ok - except there's only one windows buffer and two strings of unique data for each entry I need. I gather I can pass multiple strings to procomm on a command line invoking it so I can probably manage to figure out the web form end of it if I can get some clues on how to make the script insert the strings where I want and convert case and reformat the XXXX.XXXX to xx.xxxx.xx format for me. The ultimate goal is to get as much as possible of this happening via scripts and automation to get as little of the end user typing commands live in a router as possible. Having people who don't know what they're doing typing raw config files in routers scares me.
 
Will the dash in the first line (ip dhcp pool cm-0090.XXXX.XXXX) always be present? If so, this script should get you started:

proc main
string sLine
string sAddr1, sAddr2
string sOutput

if fopen 0 "data.txt" READ TEXT
fopen 1 "output.txt" CREATE TEXT
while not feof 0
fgets 0 sLine
if strfind sLine "ip dhcp pool"
strtok sAddr1 sLine "-" 2
fgets 0 sLine
strtok sAddr2 sLine " " 2
strfmt sOutput "%s %s" sAddr1 sAddr2
fputs 1 sOutput
endif
endwhile
endif
endproc

aspect@aspectscripting.com
 
Thanks, that looks like it should help a lot. I appreciate your help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top