Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to disconnect internet connection of my single system, connected in LAN, and I need to connect again to the internet.

How could I make this happen?

I used...
ReleaseDHCPLease and RenewDHCPLease

But it didn't work

Help me!!
Posted
Updated 18-May-11 21:38pm
v3
Comments
samueal123 17-May-11 0:30am    
Internet connection can be disconnected by unplugging the network cable.

How could i do this through c# program.

And again i need to connect to the internet connection after a while.

My system is connected with LAN, i should disconnect only my system from the internet.

Can anyone help me pls??
Dalek Dave 19-May-11 3:39am    
Edited for Grammar and Readability.

You can use InternetHangUp method of wininet.dll.

http://pinvoke.net/default.aspx/wininet/InternetHangUp.html[^]
 
Share this answer
 
Comments
Kim Togo 16-May-11 7:53am    
"Instructs the modem to disconnect from the Internet." - Okay then...
yesotaso 16-May-11 11:07am    
:)Axe on the cable - sledge on the modem - right click "the" icon and disable, all works aswell. Though 1st 2nd options may be problematic on re-connect
samueal123 17-May-11 0:35am    
@jaans: i don't need the modem to get disconnected. My system is connected in LAN and i need to disconnect only my system.
You can change "default gateway" on the computer to the computers own IP address or 0.0.0.0
 
Share this answer
 
Comments
yesotaso 16-May-11 11:12am    
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration " _
& "Where IPEnabled = True")
For Each objNetCard in colNetCards
objNetCard.ReleaseDHCPLease()
Next

From "http://msdn.microsoft.com/en-us/library/aa394595%28v=VS.85%29.aspx"
samueal123 17-May-11 0:31am    
I tried with ReleaseDHCPLease() but it didn't help me.
Kim Togo 17-May-11 2:26am    
Are the computer running with DHCP enabled?
If not, then the ReleaseDHCPLease() will not work. Again, changing default route is one way and you do not loss IP connection on local IP network.
samueal123 17-May-11 2:50am    
@Kim togo: How could i find whether my computer is running with DHCP enabled??
Kim Togo 17-May-11 2:53am    
http://doit.vuse.vanderbilt.edu/SEDCON/networks/DHCP/

Is some image on how to check.
There is no easy way. Blocking port 80 could be a simple workaround.
Disabling the network adapter is easier. But I guess you don't want that.
 
Share this answer
 
v2
Comments
samueal123 17-May-11 2:38am    
Can you please tell me how could i do that?
<pre lang="vb">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




This is my code in VB. And at last i found it
 
Share this answer
 
Comments
Dalek Dave 19-May-11 3:39am    
Useful.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900