Adding an IP address to a network card

T

tag

I'm trying to add an IP address to a pc's network card. In C++ I used
the IPHlpApi.lib's function AddIPAddress. Is there a built in way to
add an IP Address in C#?

Thanks in advance...
 
L

Leo Seccia

Hello,

don't think there is a built in way but how about
[DllImport("iphlpapi.dll", SetLastError=true)]
static extern int AddIPAddress(int Address, int IpMask, int IfIndex, out
IntPtr NTEContext, out IntPtr NTEInstance );

if unmanaged is an option then this will do the trick...

look on pinvoke.net for usage.

Leo
 
U

urkec

Leo Seccia said:
Hello,

don't think there is a built in way but how about
[DllImport("iphlpapi.dll", SetLastError=true)]
static extern int AddIPAddress(int Address, int IpMask, int IfIndex, out
IntPtr NTEContext, out IntPtr NTEInstance );

if unmanaged is an option then this will do the trick...

look on pinvoke.net for usage.

Leo

tag said:
I'm trying to add an IP address to a pc's network card. In C++ I used
the IPHlpApi.lib's function AddIPAddress. Is there a built in way to
add an IP Address in C#?

Thanks in advance...


There is also WMI and Win32_NetworkAdapterConfiguration class.
 
T

tag

Leo Seccia said:
don't think there is a built in way but how about
[DllImport("iphlpapi.dll", SetLastError=true)]
static extern int AddIPAddress(int Address, int IpMask, int IfIndex, out
IntPtr NTEContext, out IntPtr NTEInstance );
if unmanaged is an option then this will do the trick...
look on pinvoke.net for usage.

There is also WMI and Win32_NetworkAdapterConfiguration class.

Thanks for both of your suggestions. I used iphlpapi.dll and it works
okay, I noticed that I have to call it early in my program, or the NIC
card isn't changed before the socket is created...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top