Sign in to follow this  
Followers 0
Guest Ranma4703

Help with FileReadLine

3 posts in this topic

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

TCP 127.0.0.1:1059 127.0.0.1:1060 ESTABLISHED

TCP 127.0.0.1:1060 127.0.0.1:1059 ESTABLISHED

TCP 192.168.1.120:1156 63.240.202.130:6112 ESTABLISHED

TCP 192.168.1.120:1161 63.240.202.148:6112 TIME_WAIT

TCP 192.168.1.120:1168 63.240.202.76:4000 ESTABLISHED

TCP 192.168.1.120:4698 64.12.24.122:5190 ESTABLISHED

TCP 192.168.1.120:4699 205.188.10.197:5190 ESTABLISHED

TCP 192.168.1.120:4708 24.74.30.38:6667 ESTABLISHED

TCP 192.168.1.120:4718 24.207.0.199:6667 ESTABLISHED

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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)
      Msgbox(0,'test',$Ipaddr)
      ExitLoop
   EndIf
Wend
FileClose($HFILE)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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