Click here to Skip to main content
15,887,267 members
Home / Discussions / C#
   

C#

 
QuestionHelp with p/invoking iphlpapi.dll Pin
CCodeNewbie3-Feb-12 5:55
CCodeNewbie3-Feb-12 5:55 
AnswerRe: Help with p/invoking iphlpapi.dll Pin
PIEBALDconsult3-Feb-12 7:40
mvePIEBALDconsult3-Feb-12 7:40 
AnswerRe: Help with p/invoking iphlpapi.dll Pin
Luc Pattyn3-Feb-12 7:46
sitebuilderLuc Pattyn3-Feb-12 7:46 
GeneralRe: Help with p/invoking iphlpapi.dll Pin
CCodeNewbie3-Feb-12 9:45
CCodeNewbie3-Feb-12 9:45 
GeneralRe: Help with p/invoking iphlpapi.dll Pin
PIEBALDconsult3-Feb-12 11:25
mvePIEBALDconsult3-Feb-12 11:25 
AnswerRe: Help with p/invoking iphlpapi.dll Pin
Luc Pattyn3-Feb-12 15:40
sitebuilderLuc Pattyn3-Feb-12 15:40 
GeneralRe: Help with p/invoking iphlpapi.dll Pin
jschell4-Feb-12 9:47
jschell4-Feb-12 9:47 
AnswerRe: Help with p/invoking iphlpapi.dll - Going in circles Pin
CCodeNewbie5-Feb-12 2:05
CCodeNewbie5-Feb-12 2:05 
Thanks for all you comments/ideas but I am still struggling although making progress.

@PIEBALDconsult, I really like the regex idea but can't figure out how to pipe the ouput into you code.

@Luc, jschell - prior to investigating iphlpapi I was trying the Process method and have now gone back to that thanks to your suggestions. Th issues I am having though
- I still can't get the individual items to writeline or to a list
- I can't work out why connections[1]-[6] aren't populated.
- I need to connections[1].split(':') to split the host and the local port
- I need to connections[3].split(':') to split the host and the local port
- I can't get rid of the newlines between the split entries.

My code follows:
C#
Process Ns = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo("netstat");
startInfo.Arguments = "-ao";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
Ns.StartInfo = startInfo;
Ns.Start();
for (int i = 0; i < 4; i++)
    Ns.StandardOutput.ReadLine();
while (true)
{
    string Line = (Ns.StandardOutput.ReadLine());
    string[] split = Line.Split(' ');
    foreach (string s in split)
    {
        List<string> connections = new List<string>();
        connections.Add(s);
        if (s != "" || s != Environment.NewLine)
        {
            Console.WriteLine("Protocol:", connections[0]);
            Console.WriteLine("LocalIP:", connections[1]);
            Console.WriteLine("LocalPort:", connections[2]);
            Console.WriteLine("RemoteIP:", connections[3]);
            Console.WriteLine("RemotePort:", connections[4]);
            Console.WriteLine("State:", connections[5]);
            Console.WriteLine("PID:", connections[6]);
        }
    }
}

AnswerRe: Help with p/invoking iphlpapi.dll - Going in circles Pin
Luc Pattyn5-Feb-12 3:25
sitebuilderLuc Pattyn5-Feb-12 3:25 
GeneralRe: Help with p/invoking iphlpapi.dll - Going in circles Pin
CCodeNewbie6-Feb-12 5:57
CCodeNewbie6-Feb-12 5:57 
AnswerRe: Help with NETSTAT output Pin
Luc Pattyn6-Feb-12 6:25
sitebuilderLuc Pattyn6-Feb-12 6:25 
GeneralRe: Help with NETSTAT output Pin
CCodeNewbie6-Feb-12 9:23
CCodeNewbie6-Feb-12 9:23 
AnswerRe: Help with NETSTAT output Pin
Luc Pattyn6-Feb-12 9:55
sitebuilderLuc Pattyn6-Feb-12 9:55 
GeneralRe: Help with NETSTAT output Pin
CCodeNewbie6-Feb-12 10:35
CCodeNewbie6-Feb-12 10:35 
QuestionSerialPort.Close() hanging Pin
__John_3-Feb-12 5:13
__John_3-Feb-12 5:13 
AnswerRe: SerialPort.Close() hanging Pin
jschell3-Feb-12 10:57
jschell3-Feb-12 10:57 
GeneralRe: SerialPort.Close() hanging Pin
__John_5-Feb-12 22:20
__John_5-Feb-12 22:20 
QuestionBest method for putting a wait Pin
Subin Mavunkal2-Feb-12 21:08
Subin Mavunkal2-Feb-12 21:08 
AnswerRe: Best method for putting a wait Pin
OriginalGriff2-Feb-12 21:18
mveOriginalGriff2-Feb-12 21:18 
GeneralRe: Best method for putting a wait Pin
Subin Mavunkal2-Feb-12 21:26
Subin Mavunkal2-Feb-12 21:26 
AnswerRe: Best method for putting a wait Pin
OriginalGriff2-Feb-12 21:40
mveOriginalGriff2-Feb-12 21:40 
AnswerRe: Best method for putting a wait Pin
BobJanova3-Feb-12 4:48
BobJanova3-Feb-12 4:48 
AnswerRe: Best method for putting a wait Pin
Eddy Vluggen3-Feb-12 6:22
professionalEddy Vluggen3-Feb-12 6:22 
QuestionPlay DVD and cut a Video in WPF Pin
Alessio Elia2-Feb-12 9:46
Alessio Elia2-Feb-12 9:46 
AnswerRe: Play DVD and cut a Video in WPF Pin
Dean Oliver3-Feb-12 6:52
Dean Oliver3-Feb-12 6:52 

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.