Click here to Skip to main content
15,891,184 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to edit textbox that is bound with int Pin
kruegs355-Apr-12 5:11
kruegs355-Apr-12 5:11 
GeneralRe: How to edit textbox that is bound with int Pin
JOAT-MON6-Apr-12 8:28
JOAT-MON6-Apr-12 8:28 
QuestionIndexOutOfRangeExceoption while parsing a Netstat process Pin
CCodeNewbie4-Apr-12 10:46
CCodeNewbie4-Apr-12 10:46 
AnswerRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
Eddy Vluggen4-Apr-12 11:20
professionalEddy Vluggen4-Apr-12 11:20 
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
CCodeNewbie4-Apr-12 11:37
CCodeNewbie4-Apr-12 11:37 
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
CCodeNewbie7-Apr-12 13:41
CCodeNewbie7-Apr-12 13:41 
AnswerRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
Eddy Vluggen7-Apr-12 22:21
professionalEddy Vluggen7-Apr-12 22:21 
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
CCodeNewbie8-Apr-12 0:14
CCodeNewbie8-Apr-12 0:14 
Hi Eddy,

Usually it does divide. "UDP 0.0.0.0:445 *:* 4" put through
C#
if (s.Length == 6)
    {
        insns.Parameters["@Protocol"].Value = s[0];
        insns.Parameters["@LocalHost"].Value = s[1];
        insns.Parameters["@LocalPort"].Value = s[2];
        insns.Parameters["@RemoteHost"].Value = s[3];
        insns.Parameters["@RemotePort"].Value = s[4];
        insns.Parameters["@State"].Value = "0";
        insns.Parameters["@PID"].Value = s[5];
    }
becomes
s[0]=UDP
s[1]=0.0.0.0
s[2]=445
s[3]=*
s[4]=*
s[5]=0
s[6]=4

if I remove the line "insns.Parameters["@State"].Value = "0";"
the output reports "Listening" even though there is no value in the netstat cmd-line output.

Sorry this is taking a while, worked out I had to use System.Diagnostics.Debug.WriteLine instead of System.Diagnostics.Debugger.WriteLine

So, I did
C#
Process Ns = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo("netstat");
startInfo.Arguments = "-ano";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
Ns.StartInfo = startInfo;
Ns.Start();
Ns.WaitForExit();
for (int i = 0; i < 4; i++)
    Ns.StandardOutput.ReadLine();
while (true)
{
    Line = (Ns.StandardOutput.ReadLine());
    if (!string.IsNullOrEmpty(Line))
    {
        Line = Line.Trim();
        Line = Line.Replace("        ", " ");
        Line = Line.Replace("       ", " ");
        Line = Line.Replace("      ", " ");
        Line = Line.Replace("     ", " ");
        Line = Line.Replace("    ", " ");
        Line = Line.Replace("   ", " ");
        Line = Line.Replace("  ", " ");
        Line = Line.Replace("  ", " ");
        Line = Line.Replace("  ", " ");
        Line = Line.Replace(":", " ");
        Line = Line.Replace('\r', ' ');
        Line = Line.Replace('\n', ' ');
        s = Line.Split(' ');
        if (s[0] == "TCP")
        {
            if (s[1] != "0.0.0.0")
            {
                insns.Parameters["@Tstamp"].Value = DateTime.Now;
                insns.Parameters["@SysID"].Value = SID;
                insns.Parameters["@Protocol"].Value = s[0];
                insns.Parameters["@LocalHost"].Value = s[1];
                insns.Parameters["@LocalPort"].Value = s[2];
                insns.Parameters["@RemoteHost"].Value = s[3];
                insns.Parameters["@RemotePort"].Value = s[4];
                insns.Parameters["@State"].Value = s[5];
                insns.Parameters["@PID"].Value = s[6];
                NSInfo.Open();
                insns.ExecuteNonQuery();
                NSInfo.Close();
            }
       }
       if (s[0] == "UDP")
       {
            if (s.Length == 6)
            {
                insns.Parameters["@Tstamp"].Value = DateTime.Now;
                insns.Parameters["@SysID"].Value = SID;
                insns.Parameters["@Protocol"].Value = s[0];
                insns.Parameters["@LocalHost"].Value = s[1];
                insns.Parameters["@LocalPort"].Value = s[2];
                insns.Parameters["@RemoteHost"].Value = s[3];
                insns.Parameters["@RemotePort"].Value = s[4];
                insns.Parameters["@State"].Value = "0";
                insns.Parameters["@PID"].Value = s[5];

            NSInfo.Open();
            insns.ExecuteNonQuery();
            NSInfo.Close();
            }
            if (s.Length == 7)
            {
                insns.Parameters["@Tstamp"].Value = DateTime.Now;
                insns.Parameters["@SysID"].Value = SID;
                insns.Parameters["@Protocol"].Value = s[0];
                insns.Parameters["@LocalHost"].Value = s[1];
                insns.Parameters["@LocalPort"].Value = s[2];
                insns.Parameters["@RemoteHost"].Value = s[3];
                insns.Parameters["@RemotePort"].Value = s[4];
                insns.Parameters["@State"].Value = s[5];
                insns.Parameters["@PID"].Value = s[6];
            NSInfo.Open();
            insns.ExecuteNonQuery();
            NSInfo.Close();
            }
            else
            {
                foreach (string someWord in s)
                    {
                        System.Diagnostics.Debug.WriteLine("'{0}'", someWord);
                    }
            }
        }

when the timer triggered my CPU ramped up to 99% usage by my app and I had to End-Task it. Nothing was written to the Output or the Event log.
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
Eddy Vluggen8-Apr-12 0:28
professionalEddy Vluggen8-Apr-12 0:28 
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
CCodeNewbie8-Apr-12 1:12
CCodeNewbie8-Apr-12 1:12 
AnswerRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
Eddy Vluggen8-Apr-12 1:48
professionalEddy Vluggen8-Apr-12 1:48 
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
CCodeNewbie8-Apr-12 2:09
CCodeNewbie8-Apr-12 2:09 
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
CCodeNewbie8-Apr-12 8:21
CCodeNewbie8-Apr-12 8:21 
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
Eddy Vluggen8-Apr-12 8:29
professionalEddy Vluggen8-Apr-12 8:29 
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
CCodeNewbie8-Apr-12 8:33
CCodeNewbie8-Apr-12 8:33 
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
Eddy Vluggen8-Apr-12 8:56
professionalEddy Vluggen8-Apr-12 8:56 
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
CCodeNewbie8-Apr-12 8:58
CCodeNewbie8-Apr-12 8:58 
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process - update Pin
CCodeNewbie8-Apr-12 0:30
CCodeNewbie8-Apr-12 0:30 
AnswerRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
Luc Pattyn4-Apr-12 11:38
sitebuilderLuc Pattyn4-Apr-12 11:38 
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
CCodeNewbie4-Apr-12 11:41
CCodeNewbie4-Apr-12 11:41 
GeneralRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
Luc Pattyn4-Apr-12 11:57
sitebuilderLuc Pattyn4-Apr-12 11:57 
AnswerRe: IndexOutOfRangeExceoption while parsing a Netstat process Pin
V.4-Apr-12 20:39
professionalV.4-Apr-12 20:39 
Questionopen WPF within a WPF Pin
Me kiter4-Apr-12 7:22
Me kiter4-Apr-12 7:22 
QuestionQCrypto Pin
univmalik4-Apr-12 6:40
univmalik4-Apr-12 6:40 
QuestionJson serialization Pin
tfile1014-Apr-12 2:46
tfile1014-Apr-12 2:46 

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.