Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This is somehow a developer question, but as it is more related to operating systems and network connections, I will post it here and not on Stack Overflow.

I'm trying to simulate a situation when a network connection get closed because of a network problem or error, to test a behavior I implemented in one of my application. I could simply disconnect my network cable or shut down the network interface, but I made my application to reconnect immediately after this so doing that will take too long until the network will be up again (because of DHCP negotiating and etc.).

Is there any way, in Unix or OS X, to just disconnect a specific application from internet and then let it reconnect immediately? Maybe to simulate a "connection reset by peer" error or something (I'm not a pro when it comes about networking, so sorry for my newbie language).

Thank you.

share|improve this question
2  
many firewall programs can disable specific applications from using the network... have you tried them? Linux/macs are not my forte, but I know you can do it in Windows, so Im sure it can be done in them. Also, this can be easily done in a virtual machine. –  Keltari Jan 21 '13 at 13:14

1 Answer 1

Various ways to do it, but the simplest one that occurs to me is to use ifconfig (ipconfig on windows) The syntax will vary somewhat, but

ifconfig eth0 down

You could do similar things with route, by deleting the route to the app's server.

Or you could clear the arp cache, (see man arp) then have another host (real or virtual) spoof that machine's MAC.

There is a package call hping (I think in version 3 now) that can simulate various sorts of packets. You may be able to use this to set reset packets from the destination back to the host that is running the application.

So you can put it in a script

ifconfig eth0 down
sleep 5
ifconfig eth0 up

If you have the server on your network to, you can turn the process on the server off. E.g. stop the httpd server if your application is a web app.

The earlier poster about working with a firewall on a machine that your application's packets have to traansit.

Also look up injection attacks, and denial of service attacks.

If the server or an intermediate host runs linux, you and run pf on that host. By loading and unloading a given rule, you can open or close a given port/protocol/ip combination. You can also throttle a connection, allowing only so many packets per second..

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.