By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,932 Members | 1,547 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,932 IT Pros & Developers. It's quick & easy.

Stripping IP Address out of text file?

P: n/a
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.

Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Jul 21 '05 #2

P: n/a
Good Boy Patrick :-)
Thanks for not being yet another parasite using the newsgroups
to suck off the tit.
--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/
"Patrick" <pa*****@hello.com> wrote in message
news:OL**************@TK2MSFTNGP15.phx.gbl...
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

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.