# Simple network program



## G-Stress (Feb 4, 2008)

I created a little network troubleshooting utility via a batch script here: http://forums.techguy.org/dos-pda-other/679299-ipconfig-bat.html

Now I'm looking to step it up a bit. I'd like to create a nice gui in VB or C/C++ which ever is the easiest. I have no real programming experience, but I'd like to get started. Was wondering if someone could give me an example of just creating a simple program to ping. I should be able to figure out the rest if I can get an example to ping.

I also found this: http://vbnet.mvps.org/index.html?code/internet/ping.htm but is it really this complicated just to ping? It takes all of that code?


----------



## -Fabez- (Jul 28, 2008)

Both are pretty easy to create gui's in if you have visual studio express. It comes down to which ever coding language you feel most comfortable in. With c++ for example you could use system("ping <ip address>") and format the results. With c++ the command system() means execute the command in the brackets as if it has been typed at the command prompt. If you need any more help i will be happy to help


----------



## G-Stress (Feb 4, 2008)

-Fabez- said:


> Both are pretty easy to create gui's in if you have visual studio express. It comes down to which ever coding language you feel most comfortable in. With c++ for example you could use system("ping <ip address>") and format the results. With c++ the command system() means execute the command in the brackets as if it has been typed at the command prompt. If you need any more help i will be happy to help


Thanks alot for the quick response. So I could do say

system("ping <yahoo.com>") in notepad and use some sort of c++ compiler and it will ping yahoo when executed? If you don't mind and are familiar what about VB? I think that is probably gonna be the easiest for me to start in. I am gonna get visual studio express also.


----------



## -Fabez- (Jul 28, 2008)

Thats okay. Kind of but you would type system("ping yahoo.com") into the compiler and compile it, the resultant exe will then ping yahoo.com when run. If i wouldnt mind what? And yes i am familiar in Visual Basic as well as Visual C++


----------



## G-Stress (Feb 4, 2008)

Sorry, I meant if you wouldn't mind, could you provide me an example in VB on how I would code to ping. I think I will start with VB it seems easiest.


----------



## -Fabez- (Jul 28, 2008)

Here we go 

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Reply As System.Net.NetworkInformation.PingReply
Dim Test As New System.Net.NetworkInformation.Ping()
Reply = Test.Send("127.0.0.1")
'Reply.Address
'Reply.Buffer
'Reply.Options
'Reply.RoundtripTime
'Reply.Status
End Sub
End Class

If you need any more clafication of any sort I will be happy to explain it to you


----------



## G-Stress (Feb 4, 2008)

Yes!  Thank you so much  Now that I see this I should be able to figure out how to code the rest of the commands, at least I'm gonna have fun trying. I will definitely post back results and appreciate all the help.

Thanks again


----------



## G-Stress (Feb 4, 2008)

Hmmm... I just tested it out and assume it works, although it gives me no results. I assume the


```
'Reply.Address
'Reply.Buffer
'Reply.Options
'Reply.RoundtripTime
'Reply.Status
```
is commented out for the possibility of the results just how I want to format them. I figured out how to add a button and click the button to ping, but I'm not exactly sure how to add some type of field to display the results. I'm also not sure what would look best, a text box, listbox or what would look good displaying the results.

What im wanting is I guess a text field to type a host/ip to ping and then click a button that says ping and then something to display the results. You won't believe that I couldn't even find an example this informative on google.


----------



## -Fabez- (Jul 28, 2008)

Nice one  Yes they are the properties the ping returns for you. So for example you would make the text fields text, Pinged + Reply.Address and so on and so forth. And you do get results, they are stored in Reply for you to use  And to change the host/ip you make a text box on the form as well as a button. When the user clicks the button, it stores the text box's value in a variable and you use that variabe for the ping, kind of like this.


```
Dim HostOrIp = TextBox.text
Reply = Test.Send(HostPOrIp)
```
Hope it works for you


----------



## G-Stress (Feb 4, 2008)

Hmmm... I guess I'm still just a bit lost. Here's what I got so far.


```
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Reply As System.Net.NetworkInformation.PingReply
        Dim Test As New System.Net.NetworkInformation.Ping()
        Dim HostP0rIp = TextBox.Text
        Reply = Test.Send(HostP0rIp)
        'Reply.Address
        'Reply.Buffer
        'Reply.Options
        'Reply.Roundtrip()
        'Reply.Status
```
Is HostP0rIP like a null value you meaning whatever I entered into a text box it would ping?
With the above I got a build error here "Dim HostP0rIP = TextBox.text" something wrong with TextBox.text it says "Reference to a non-shared member requires an object reference"


----------



## -Fabez- (Jul 28, 2008)

Your not lost  I forgot to tell you its, Dim HostP0rIP = TextBox.text.ToString , as text is a property of TextBox so it counts as an object. Can you ever forgive me


----------



## G-Stress (Feb 4, 2008)

hmmm... I added that ToString and i'm still getting the same error. I guess I might be adding the code in the "wrong place". For example should this code be placed "inside" a textbox, like if I start a new project, basic form, add 1 textbox and double click it to add code?


----------



## -Fabez- (Jul 28, 2008)

'Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, This line is commented out, is there any reason for this? I will try and create something for you to go on if you want


----------



## G-Stress (Feb 4, 2008)

I was just trying some things out. I tried uncommenting with the same result. Still seems to be some issue with "TextBox.text"

If you get bored and wouldn't mind I would like to see a working example of a basic form with a field to enter a host to ping and a field that displays the statistics. Once I see the code for that and working I should understand alot more.

Thanks again for all the help.


----------



## -Fabez- (Jul 28, 2008)

Well im bored now so I will have a go for you


----------



## G-Stress (Feb 4, 2008)

Excellent. Looking forward to it


----------



## avisitor (Jul 13, 2008)

I'm equally bored, and it seems like a good idea, actually something I've thought about doing. I'll whip one up in C#. I do have VS2008 Pro, so you may or may not be able to use my project exactly.


----------



## G-Stress (Feb 4, 2008)

Great  I do have VS2008, just I'm just getting into programming. I have VTC courses I've watched a bit of, but seeing something work that interests me is how I understand best.


----------



## avisitor (Jul 13, 2008)

Does anyone know how to read from the StandardOutput of a process asynchronously? That's one thing I want to know, however, here's draft 1. Note, if you run a tracert, be prepared to wait. It appears to hang but it really hasn't. It pops a message box to tell you it may take some time which has the effect of causing a redraw. I was thinking of encapsulating the other stuff in a thread, but this is the first quick attempt.

I have VS2008 Pro, that's a paid version, I believe this project should be compatible with the express editions, however, not all of the projects that I create in Pro are. It's done in C#, so you'll need that express edition if you're using the express editions.


----------



## avisitor (Jul 13, 2008)

Do note that saving the log is not yet implemented. Take a look at the code, the way some of the stuff (executing the commands) was implemented is really kind of nifty.


----------



## avisitor (Jul 13, 2008)

This version has support for writing the log in basic form:

Needs more work, but off to bed for me. I'll work more on it tomorrow.


----------



## avisitor (Jul 13, 2008)

Moving further along: now the test components run in their own thread so the UI doesn't hang when the tests are running. This stops the program from going unresponsive when tests are going. I still want to do an asynchronous read from StandardOutput. Anyone know how to do it?


----------



## IMM (Feb 1, 2002)

> I still want to do an asynchronous read from StandardOutput. Anyone know how to do it?


Is this link any help? 
http://msdn.microsoft.com/en-us/library/system.diagnostics.process(VS.80).aspx
(there are some links to sourceforge code at the bottom)

maybe also these?
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.cancelerrorread.aspx
http://msdn.microsoft.com/en-us/library/system.diagnostics.datareceivedeventhandler.aspx
setting up pipes are another thought ?


----------

