views:

69

answers:

1

I need to check if a TCP/IP route already exists from my application and add the route if it doesn't. Now I'm running the

route add <destination network ip address> MASK <mask> <gateway ip address>

with a Process.Start() and that's fine for me. However, as I'm elevating the route command with a "runas" verb, I need to check first if the route is already configured in order to avoid running the elevated command again.

Does anybody know how to get the TCP/IP routing information using .NET Framework? (I don't want to run route print with a Process.Start() and parse the output)

Thank you in advance!!

+1  A: 

I think you have to rely on IpHlpApi.Dll

Here is a tutorial on how to use it with P/Invoke

Eric
Thanks for the link, I think it's the solution but my question is, why that information is not available to the .NET framework directly?
Eugenio Miró
I think it is possible to use System.Management to access WMI. Also, I guess a pure .NET solution would only be a wrapper around the IpHlpApi.dll so they didn't bother
Eric
Yeah, you're right, but having a wrapper is better than nothing :P, thank you very much for your answer.
Eugenio Miró