Thread: Disabling a network interface card to disconnect from LAN..

  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,210
    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
    28,413
    Moved to Networking/Device Communication.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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,732
    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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

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, 05: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