Stripping IP Address out of text file?

  • Thread starter Thread starter Patrick
  • Start date Start date
P

Patrick

Hello, after learning that I was taking a class in VB.NET, I have been
drafted to solve all my companies VB/scripting problems - hey, I should know
everything; I've already taken 6 classes ;) I should have been quiet about
it, but then I would never be reimbursed. Oh well.

I have been asked to write a program to ping a NetBIOS name, get the IP, and
compare the 3rd octet to a list to get the computer's location. So far, I
can ping the IP, save the output to a text file, and open the file, but I am
having trouble stripping out the IP address. My code is as follows:

Private Sub ConvertButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ConvertButton.Click

' Click a button, it takes the value of NetBiosBox and pings it, then

' saves the output to c:\vb\test2.txt

Dim RedirectFile As Object
RedirectFile = "c:\vb\test2.txt"
Shell(Environ$("comspec") & " /k ping " & Me.NetBiosBox.Text & " > """ &
RedirectFile & """", AppWinStyle.Hide)

' Here is where I open the file - but how do I get the data I need? All
samples I have assume fixed file sizes, etc.

FileOpen(1, "c:\vb\test2.txt", OpenMode.Binary, OpenAccess.Default,
OpenShare.Shared)

FileClose(1) ' Close file.

I can do comparisons, I'm pretty sure the docs I have for opening files are
thorough, and I feel I'm on the right track. Any help with the stripping out
of the IP would be appreciated. Thanks! If this is the wrong place for
questions like this - let me know where.
 
Well, since no one answered, here is what I came up with for future
frustrated student reference. Wasn't as hard as I thought it was - just used
rudimentary info on Sequential files and a crash course in string
manipulation.

Private Sub OpenFileButton_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles OpenFileButton.Click

Dim strline as String
Dim stripOutput As String
Dim objStreamReader As System.IO.StreamReader
' strIP(intX) will be an array we create from files read
Dim intX As Integer
Dim intY As Integer
Dim strZ As String
If System.IO.File.Exists("c:\windows\temp\test.txt") Then
objStreamReader =
System.IO.File.OpenText("c:\windows\temp\test.txt")
'TestOutputLabel.Text = objStreamReader.ReadLine()
Do Until objStreamReader.Peek = -1
strline = objStreamReader.ReadLine()
intX = intX + 1
If intX = 7 Then
stripOutput = strline
stripOutput = stripOutput.Replace("Reply from ", "")
stripOutput = stripOutput.TrimEnd(":")
intY = stripOutput.IndexOf(":")
strZ = stripOutput.Substring(intY)
stripOutput = stripOutput.Replace(strZ, "")
End If
'MessageBox.Show(strline, "Line", _
'MessageBoxButtons.OK, MessageBoxIcon.Information)
Loop
objStreamReader.Close()
Me.TestOutputLabel.Text = stripOutput

Else
MessageBox.Show("The output file has not been created yet.",
"Sorry", _
MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
 
Good Boy Patrick :-)
Thanks for not being yet another parasite using the newsgroups
to suck off the tit.
 
Back
Top