Click here to Skip to main content
15,895,011 members
Home / Discussions / C#
   

C#

 
GeneralRe: Need help with my very first c# application Pin
S Houghtelin7-Oct-10 10:01
professionalS Houghtelin7-Oct-10 10:01 
GeneralRe: Need help with my very first c# application Pin
OriginalGriff7-Oct-10 9:20
mveOriginalGriff7-Oct-10 9:20 
GeneralRe: Need help with my very first c# application Pin
turbosupramk37-Oct-10 10:01
turbosupramk37-Oct-10 10:01 
GeneralRe: Need help with my very first c# application Pin
turbosupramk37-Oct-10 10:12
turbosupramk37-Oct-10 10:12 
GeneralRe: Need help with my very first c# application Pin
OriginalGriff7-Oct-10 21:34
mveOriginalGriff7-Oct-10 21:34 
GeneralRe: Need help with my very first c# application Pin
turbosupramk38-Oct-10 4:28
turbosupramk38-Oct-10 4:28 
GeneralRe: Need help with my very first c# application Pin
OriginalGriff8-Oct-10 4:51
mveOriginalGriff8-Oct-10 4:51 
GeneralRe: Need help with my very first c# application Pin
turbosupramk313-Oct-10 7:20
turbosupramk313-Oct-10 7:20 
Here is my latest code, thanks to all that helped


using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;


namespace Examples.System.Net.NetworkInformation.PingTest
{
    public class PingExample
    {
        public static void Main(string[] args)
        {
            const string f = @"c:\temp\servernames.txt";
            List<string> servers = new List<string>();

            Ping pingSender = new Ping();
            PingOptions options = new PingOptions();
            //PingCompletedEventArgs e = new PingCompletedEventArgs();
            string line = null; //line in a file
            PingReply reply = null; // variable reply is set to null and referenced to the object type PingReply
            //string lineerror = null;

            // Use the default Ttl value which is 128,
            // but change the fragmentation behavior.
            options.DontFragment = true;

            // Create a buffer of 32 bytes of data to be transmitted.
            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            byte[] buffer = Encoding.ASCII.GetBytes(data);
            int timeout = 250;
            using (StreamReader r = new StreamReader(f))
            {
                // 3
                // Use while != null pattern for loop
                while ((line = r.ReadLine()) != null)
                {
                    // 4
                    // Insert logic here.
                    // ...
                    // "line" is a line in the file. Add it to our List.
                    if (string.IsNullOrEmpty(line))
                    {
                        // 3
                        // Test with IsNullOrEmpty
                        //lineerror = "Line appears to be empty";
                    }
                    else
                    {
                        servers.Add(line);
                    }
                }//end of while
            }//end fo using

            //string[] arr = new string[] { "server1", "server2", "server3" }; // server names you want to ping

            foreach (string i in servers)
            {

                Console.WriteLine(i);
                for (int retries = 0; retries < 4; retries++)
                {
                    try
                    {
                        reply = pingSender.Send(i, timeout, buffer, options); // variable reply is assigned

                        if (reply.Status == IPStatus.Success)
                        {
                            Console.WriteLine("Reply from {0}", reply.Address.ToString() + ": bytes=" + reply.Buffer.Length + " time=" + reply.RoundtripTime + "ms" + " TTL=" + reply.Options.Ttl);
                            //Console.WriteLine(reply.Status);
                            //Console.WriteLine("Bytes {0}", reply.Buffer.Length);
                            //Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
                            //Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
                            //Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
                        }
                        //else
                        //{
                        //    Console.WriteLine(lineerror);
                        //}
                    }
                    catch (PingException e)
                    {
                       Console.WriteLine("Ping failed: " + e.Message);
                    }



                }// end of for

                Console.WriteLine();
            }//end of foreach
            Console.ReadLine();
        }//end of Main

    }//end of PingExample

}

GeneralRe: Need help with my very first c# application Pin
S Houghtelin7-Oct-10 9:16
professionalS Houghtelin7-Oct-10 9:16 
AnswerRe: Need help with my very first c# application Pin
Nish Nishant7-Oct-10 8:17
sitebuilderNish Nishant7-Oct-10 8:17 
AnswerRe: Need help with my very first c# application Pin
MasttsaM13-Oct-10 22:43
MasttsaM13-Oct-10 22:43 
QuestionAbout creating Editable(fillable) PDF-forms Pin
sameermaske7-Oct-10 4:04
sameermaske7-Oct-10 4:04 
AnswerRe: About creating Editable(fillable) PDF-forms Pin
Ennis Ray Lynch, Jr.7-Oct-10 6:26
Ennis Ray Lynch, Jr.7-Oct-10 6:26 
QuestionParsing a text file. Pin
jenya77-Oct-10 3:21
jenya77-Oct-10 3:21 
AnswerMessage Closed Pin
7-Oct-10 3:41
stancrm7-Oct-10 3:41 
GeneralRe: Parsing a text file. Pin
jenya77-Oct-10 3:57
jenya77-Oct-10 3:57 
GeneralRe: Parsing a text file. Pin
#realJSOP7-Oct-10 23:41
mve#realJSOP7-Oct-10 23:41 
AnswerRe: Parsing a text file. Pin
PIEBALDconsult7-Oct-10 16:28
mvePIEBALDconsult7-Oct-10 16:28 
QuestionMicrosoft.Office.Interop.Excel BorderAround2 crash Pin
Blubbo7-Oct-10 2:58
Blubbo7-Oct-10 2:58 
AnswerRe: Microsoft.Office.Interop.Excel BorderAround2 crash Pin
Dave Kreskowiak7-Oct-10 3:44
mveDave Kreskowiak7-Oct-10 3:44 
GeneralRe: Microsoft.Office.Interop.Excel BorderAround2 crash Pin
Blubbo7-Oct-10 4:02
Blubbo7-Oct-10 4:02 
GeneralRe: Microsoft.Office.Interop.Excel BorderAround2 crash Pin
Dave Kreskowiak7-Oct-10 4:42
mveDave Kreskowiak7-Oct-10 4:42 
GeneralRe: Microsoft.Office.Interop.Excel BorderAround2 crash Pin
Blubbo7-Oct-10 4:49
Blubbo7-Oct-10 4:49 
GeneralRe: Microsoft.Office.Interop.Excel BorderAround2 crash Pin
Dave Kreskowiak7-Oct-10 6:04
mveDave Kreskowiak7-Oct-10 6:04 
GeneralRe: Microsoft.Office.Interop.Excel BorderAround2 crash Pin
Luc Pattyn7-Oct-10 6:29
sitebuilderLuc Pattyn7-Oct-10 6:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.