?
Solved

Enable/Disable NIC to simulate network issue

Posted on 2011-09-20
4
Medium Priority
?
793 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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