Jump to content

Help with FileReadLine

Guest Ranma4703

Recommended Posts

Guest Ranma4703

I am trying to use FileReadLine to get a specific part of a text file. The part of the text file I am trying to get is an IP address. Here is the format of the text file:

Active Connections

Proto Local Address Foreign Address State










I want to be able to get a specific IP address, preferable just the IP address, without the ESTABLISHED or TCP in there. Is there a way to get a specific line? I know I'm not being very clear... I'm sorry, I don't know exactly how to say it. Like, can I say get the line that ends in 4000?

Any help is appreciated. :D

Link to comment
Share on other sites

A good place to start would be to set up a loop to read the lines of the file. Depending on what you want to do, you could either test the lines as you read them, or store them in an array to do more than one test and display what information you are interested in.

If you just need any lines that contain the text "4000" then you could set up a loop to do the following:

  • Read the next line into a variable by use of the FileReadLine($file) call
  • Test for the End Of File error that FileReadLine could set. If it is set, you may want to tell the user the text was not found and then exit
  • Check if it has the text 4000 in it by using the StringInStr call
  • If you found a line containing the text 4000, you can take various parts that interest you by using the fact that each set of information appears to be delimited by a space. Just use StringInStr to find the Nth occurance of a space, then N+1th occurance of a space, and StringMid to read the data inbetween.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

  • Developers

This would do it :

Global $Ipaddr = ""
$HFILE = FileOpen("test.txt", 0)
If $HFILE = -1 Then Exit
While 1
   $Irec = FileReadLine($HFILE)
   If @error then ExitLoop
   If StringInStr($irec,":4000 ESTABLISHED") Then
      $irec = StringTrimLeft($irec,4) 
      $Ipaddr = StringTrimLeft($irec,StringInStr($irec," "))
      $Ipaddr = StringLeft($Ipaddr,StringInStr($Ipaddr,":")-1)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
Live for the present,
Dream of the future,
Learn from the past.

Link to comment
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...