Solved

Enable/Disable NIC to simulate network issue

Posted on 2011-09-20
4
720 Views
Last Modified: 2012-05-12
I trying to simulate network failure using Java. For one of the scenarios, once an application server starts and listens to an IP, I would like to simulate a failure by disabling the NIC. Once the test is done, I need to ensure the NIC is enabled.

Any pointers or sample code ?
0
Comment
Question by:ctoan
  • 3
4 Comments
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
What kind of sample code you expect for such testing?
0
 
LVL 1

Author Comment

by:ctoan
Comment Utility
Sorry, I should have mentioned, this will be automated testing. So I am looking for sample code to disable the NIC and then re-enable it.
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
Comment Utility
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility

check also here:
http://bytes.com/topic/c-sharp/answers/540479-how-dis-enable-network-adapter

This is not about java - but all these commands you can try to
execute form you java code using
Runtime.getRuntime().exec(...)


S. Lorétan
re: How to Dis/Enable Network Adapter?
Hi,

You can disable a network adapter with this shell command:

netsh interface set interface "Network Adapter name" DISABLED

And enable it with

netsh interface set interface "Network Adapter name" ENABLED

This works only under Windows 2003 Server. The problem with Windows 2000/XP
is because the Netshell tools treats network adapters as dedicated
interfaces, and dedicated interfaces can't be enabled or disabled. There is
a workaround if you want to prevent traffic from being passed by the network
adapter. You can use netsh to set a different (private) IP address, which
virtually disable the network adapter.

netsh interface ip set address "Network Adapter name" static (ip address)
(subnet mask) (default gateway) (metric)

And to virtually enable it, you can simply reset its IP with the DHCP

netsh interface ip set address "Network Adapter name" source=dhcp

I hope this helps. Sorry for my english.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now