0

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

Edited by samueal: n/a

3
Contributors
17
Replies
19
Views
5 Years
Discussion Span
Last Post by samueal
Featured Replies
  • 1

    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: [LIST] ip: 192.168.1.100 netmask: 255.255.255.0 gateway: 192.168.1.1 [/LIST] your modified setting: [LIST] [*]gateway: 192.168.1.255 [/LIST] this method still lets u use the … Read More

0

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

0

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#

0

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!!

0

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);
               
}
0

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

0

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!!!

0

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

0

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

0

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??

1

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;
                    }
                }
            }
        }
0

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

0
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
0

Thanks for ur effort pitic

Edited by samueal: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.