I need to disconnect internet connection of a single system which I'm using now,connected in LAN. And I need to Connect again to the internet.

How could i make this. I used

ReleaseDHCPLease

and

RenewDHCPLease

But it didn't work
Help me

Have you gone through this link.this link.. and this link

No, it didn't help me.

I have connected my system in LAN.
Could i know how can i disable my system from LAN connection. How Could i do this by C# program

check this link it has some similar information regarding enabling and disabling LAN connection in c#.... And if you are using DHCP then follow this link

check this link it has some similar information regarding enabling and disabling LAN connection in c#.... And if you are using DHCP then follow this link

I don't know whether mine is DHCP , How could i find that..

The link which you gave is in VB, I need it in C#

check this link it has some similar information regarding enabling and disabling LAN connection in c#.... And if you are using DHCP then follow this link

I tried this link.. (i.e) ReleaseDHCPLease, but it didn't work!!

Can you give your code?

Can you give your code?

ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
 
ManagementObjectCollection objMOC = objMC.GetInstances();
         
foreach (ManagementObject objMO in objMOC)
{
            
objMO.InvokeMethod("ReleaseDHCPLease", null, null);
               
}

Can you give the code to connect with LAN? if you have otherwise tell the main success scenario of your project

Actually What i need to do is to Disconnect Internet connection of single system temporarily.. Since i have connected three systems through LAN,I guess that disconnecting the LAN connection will disconnect internet connection of that particular system!!!

Am I clear?

To tell in simple words, unplugging the LAN Wire manually will disconnect internet. I need to do this through program!!!

Check this link i think it is most appropriate one ..... Actually I haven't done this type of work so I can just point you to answer not give you right answer

It contains an assembly class library and a test project which includes that assembly class just check and if working add the dll of assembly class library in your project and use its funcitons

It contains an assembly class library and a test project which includes that assembly class just check and if working add the dll of assembly class library in your project and use its funcitons

I could not get it. Can you help me??

if you need to disable your internet connection the simplest way is to change your gateway
to some ip that doesn't provide the functionality.

ex:

your curent settings:

  • ip:
  • 192.168.1.100

  • netmask:
  • 255.255.255.0

  • gateway:
  • 192.168.1.1

your modified setting:

this method still lets u use the local network. if you want to disable that too just change your ip address too.


sample code to change ip address

public void setIP(string ip_address, string subnet_mask)
        {
            ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection objMOC = objMC.GetInstances();

            foreach (ManagementObject objMO in objMOC)
            {
                if ((bool)objMO["IPEnabled"])
                {
                    try
                    {
                        ManagementBaseObject setIP;
                        ManagementBaseObject newIP =
                            objMO.GetMethodParameters("EnableStatic");

                        newIP["IPAddress"] = new string[] { ip_address };
                        newIP["SubnetMask"] = new string[] { subnet_mask };

                        setIP = objMO.InvokeMethod("EnableStatic", newIP, null);
                    }
                    catch (Exception)
                    {
                        throw;
                    }


                }
            }
        }

sample code to change gateway

public void setGateway(string gateway)
        {
            ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection objMOC = objMC.GetInstances();

            foreach (ManagementObject objMO in objMOC)
            {
                if ((bool)objMO["IPEnabled"])
                {
                    try
                    {
                        ManagementBaseObject setGateway;
                        ManagementBaseObject newGateway =
                            objMO.GetMethodParameters("SetGateways");

                        newGateway["DefaultIPGateway"] = new string[] { gateway };
                        newGateway["GatewayCostMetric"] = new int[] { 1 };

                        setGateway = objMO.InvokeMethod("SetGateways", newGateway, null);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
        }

Thanks a lot pitic.. But i solved it by myself. I used a VB program.

Public Shared Sub ToggleWirelessConnection()
        For Each verb As Shell32.FolderItemVerb In WirelessConnectionFolderItem.Verbs
            If verb.Name = "En&able" OrElse verb.Name = "Disa&ble" Then
                verb.DoIt()
                Exit For
            End If
        Next
        Threading.Thread.Sleep(1000)
    End Sub

Thanks for ur effort pitic

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.