Solved

Enable/Disable NIC to simulate network issue

Posted on 2011-09-20
4
775 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 47

Expert Comment

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

Author Comment

by:ctoan
ID: 36571247
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
ID: 36571251
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36571268

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

728 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