Disabling a network interface card to disconnect from LAN..

This is a discussion on Disabling a network interface card to disconnect from LAN.. within the Networking/Device Communication forums, part of the General Programming Boards category; Hi. Is there any possible way in which i can disable and enable the NIC using C or C++ code? ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    6

    Smile Disabling a network interface card to disconnect from LAN..

    Hi.
    Is there any possible way in which i can disable and enable the NIC using C or C++ code?
    Where can i get such codes??
    Do other languages perform such functionality. If yes, which are they?

    Thanks..

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Quote Originally Posted by elroy View Post
    Hi.
    Is there any possible way in which i can disable and enable the NIC using C or C++ code?
    Depends on what you mean by "disable" and "enable". Whatever you wish to do to it is dependent upon the O/S. Check out what your O/S can do to the NIC card. It will be limited to your program's access, as well as other factors.

    Quote Originally Posted by elroy View Post
    Where can i get such codes??
    MSDN for Windows. For *nix systems.... check man pages and probably 100 other areas.

    Quote Originally Posted by elroy View Post
    Do other languages perform such functionality. If yes, which are they?

    Thanks..
    Any language that can directly access O/S APIs.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,980
    Moved to Networking/Device Communication.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    One way of doing this is to set the Default Gateway to the loopback interface 127.0.0.1

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    if your are on *nix u could use this command

    Code:
    ifconfig eth0 down
    ssharish20058

  6. #6
    Registered User
    Join Date
    May 2007
    Posts
    6

    Disable network card

    >>One way of doing this is to set the Default Gateway to the loopback interface 127.0.0.1


    How do we do this using C?
    Any special primitives available?? I'm doing it on the Windows platform.

  7. #7
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    Here is the link to Network management using WMI http://msdn2.microsoft.com/en-us/library/aa394595.aspx

    And this is the link http://msdn2.microsoft.com/en-us/library/aa394558.aspx to C++ samples on using WMI. I don't think it is too hard to modify them into C-code
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  8. #8
    Registered User
    Join Date
    May 2007
    Posts
    6
    >>One way of doing this is to set the Default Gateway to the loopback interface 127.0.0.1


    How do i enable the network card after doing this??

  9. #9
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    Quote Originally Posted by elroy View Post
    >>One way of doing this is to set the Default Gateway to the loopback interface 127.0.0.1


    How do i enable the network card after doing this??
    This will not disable network card - just prevent the packets for exiting the subnet...

    To enable the default packets routing - just reset the address to the old value (you should store it before overwriting)...

    And this will not work if the DHCP is ON, I suppose
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise Unwanted Output
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2008, 04:07 AM
  2. Vector out of range program crash.
    By Shamino in forum C++ Programming
    Replies: 11
    Last Post: 01-18-2008, 04:37 PM
  3. Segmentation Fault - aaaaaaaah!
    By yogibear in forum C Programming
    Replies: 6
    Last Post: 10-01-2007, 03:21 AM
  4. Blackjack
    By Tommo in forum C Programming
    Replies: 10
    Last Post: 06-20-2007, 08:07 PM
  5. How can I access a struct (from a header file)?
    By loxslay in forum C++ Programming
    Replies: 3
    Last Post: 10-07-2006, 01:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21