Solved

Enable/Disable NIC to simulate network issue

Posted on 2011-09-20
4
764 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java exception bubble up 2 24
Tomcat: Unable to run tomcat service. 2 30
Java: anonymous class 4 38
Need help aligning JRadioButton that put in a box using GridBagLayout 2 27
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

726 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