473,378 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Stripping IP Address out of text file?

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
2 2268
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andy Jefferies | last post by:
I'm having problems stripping out the whitespace at the beginning of a particular element. In the XML snippet I've highlighted tabs and returns as ^I and ^M respectively: <para> ^I ^I ...
3
by: Andy B | last post by:
I've tried using Trim or RTrim to strip trailing space characters from my data. When I check on the transformed data space characters are still there. We have an address table containing two...
258
by: Terry Andersen | last post by:
If I have: struct one_{ unsigned int one_1; unsigned short one_2; unsigned short one_3; }; struct two_{ unsigned int two_1;
16
by: John Smith | last post by:
Hi all Why doesn't this seem to work? void stripnl(char *sz) { char *nl; nl = strchr(sz, '\n'); if (nl) {
4
by: Lu | last post by:
Hi, i am currently working on ASP.Net v1.0 and is encountering the following problem. In javascript, I'm passing in: "somepage.aspx?QSParameter=<RowID>Chèques</RowID>" as part of the query...
2
by: Patrick | last post by:
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...
4
by: Spondishy | last post by:
Hi, I'm looking for help with a regular expression and c#. I want to remove all tags from a piece of html except the following. <a> <b> <h1> <h2>
1
by: vunet.us | last post by:
I want to strip email from the text. Some of my users may send me a string: str = "This is email 1: me@me.com and here is email 2: <a href="mailto:me@me.com">me@me.com</a>" How do I parse the...
7
by: Benway | last post by:
Hey all, I have a file name like Eng-Cat-01-01-01.txt. I need to do a loop that starts stripping the letters from the front of this file name (which I'll store as a variable) until it reaches the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.