Link to home
Start Free TrialLog in
Avatar of ctoan
ctoan

asked on

Enable/Disable NIC to simulate network issue

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 ?
Avatar of for_yan
for_yan
Flag of United States of America image

What kind of sample code you expect for such testing?
Avatar of ctoan
ctoan

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

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.