Re: [BATCH WORLD] Alternative for find
- Usually with this kind of stuff, getting the output in a known state is the big thing, at least to me. So by parsing the output of the netstat command and splitting the fields up, you have a pridictable field pattern. In the examples I sent, you have all the info there, so you can use the tokens function of a for loop to output the fields that have the info you want. It is not uncommon for me to have a half dozen files that eventually get the output I want. Sometimes I am building a final command arugument and sometimes I am just recording info.
In the case of the netstat -an output, you have four fields if you use the tab delimited methond: Protcol, local address with port number, foreign address with port number and state. So that gives you %%a through %%d to manipulate. If you want to divide up the address/port, you need to do some further parsing. I chose to make the dilimiter a colon, which then gave me the option of using %%b %%c for the local address/port and %%d and %%e which is the foreign address/port. That info can be simply piped to a file and you have a record of each address and port. Futher parsing will give you each address that has an 80 in the port field.
I hope this gives you some help or points you to the right direction. When I parse the ouput on my computer using the method I outlined in an earlier message, I come up with the following in a text file:
24.266.47.195 3455 188.8.131.52 80
This is the only address that is using port 80 on my machine at the time the netstat command was run. The column on the right are local and the ones on the left are foreign. I know this because the output from the netstat -an was consistant. Since we are placing them in variables, we can sort them in any order we want. The above was just the default from left to right.
Hope this helps.
"phoenician_2003" <phoenix@...> wrote:
>That would work, if not for the fact that once its all redirected__________________________________________________________________
>into yet another text file, I'll have no way of knowing which IP
>addresses with port 80 are from the Local Address column only from
>the netstat -an. Unless I am missing what it is you are proposing.
The NEW Netscape 7.0 browser is now available. Upgrade now! http://channels.netscape.com/ns/browsers/download.jsp
Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/
- Originally to: phoenician_2003
> That would work, if not for the fact that once its all redirectedI use REXX to do this in OS/2. I know there is REXX for windows, but the
> into yet another text file, I'll have no way of knowing which IP
> addresses with port 80 are from the Local Address column only from
> the netstat -an. Unless I am missing what it is you are proposing.
structure might provide you clues how to do it in other script languages....
/* Sets environment variable (DYNIP) with Dynamic IP Address */
/* Must be connected to internet for this to work */
call RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
/* Sets variable ip to Dynamic IP Address using NETSTAT */
'@netstat -a|rxqueue /FIFO'
parse pull 'addr' ip rest
/* Sets environment variable DYNIP to Dynamic IP Address */
dummy = value('DYNIP',ip,'OS2ENVIRONMENT')
/* Checking that it's all working */
say 'DYNIP environment variable set to:' value('DYNIP',,'OS2ENVIRONMENT')
/* Write DYNIP to temporary file */
call SysFileDelete 'z:\dynip'
rc = lineout('z:\dynip',ip,1)