Managing two ethernet ports

I need to do a project which contains two ethernet ports, it should forward the data packet one from the other by changing meta data of the packet. I have purchased Arduino MEGA2560 board and two ethernet modules. is it possible to connect and have two ethernet interfaces ? or if not, is it possible to use usb port to communicate with the pc (like a ethernet connection) ? what methods that I have to do in programming to use usb communication ? Thanks in advanced.

Can u tell us why do you need two ethernet connection?
do u need to connect ur arduino with two different network,or only with two pc?or do u need more than four sockets?
I maka these question because probably u don't need TWO ethernet connection..

I want to connect two PCs. what I'm going to build is an anonymous communication (proxy). The communication can be between two PCs or router to PC. (via Ethernet cable). The arduino device will be act as intermediate device.

You should be able to do that with one ethernet interface using two sockets. This is a ftp client sketch that uses two sockets on one ethernet shield.

You should be able to do that with a web server/client combination, rather than command and data ports (sockets).

I guess what you wanna to do is a transparent proxy. The Arduino will not be flexible and probably also not fast enough to do so. Choose an embedded linux platform to do such things, probably the cheapest are the Linksys WRT54GL boxes using an alternative firmware like OpenWRT. It's much more flexible and a lot more powerful.

pylon is right. If that is your intent, it is not enough. My slowest router is 300MHz with 32M SRAM memory.
I like Mikrotik, but I think that is just a matter of opinion.

SurferTim:
You should be able to do that with one ethernet interface using two sockets. This is a ftp client sketch that uses two sockets on one ethernet shield.
Uploading file from SD card to remote server? - #15 by SurferTim - Networking, Protocols, and Devices - Arduino Forum

You should be able to do that with a web server/client combination, rather than command and data ports (sockets).

In this solution, can you please explain how to connect two machines at the same time to the arduino device ?

pylon: yeah, it's a transparent proxy. Since I'm doing this for a project, I can't use any in built routers, aps or switches. I'm not worrying about the speed and performance. Is there a way to manage this with lowest functionality by using arduino ? all I need is to connect two machines and make a communication. As an alternative it's ok to use the usb port to connect one machine, but how can I make it possible ? please help

You should get a web server running, then a web client. The ethernet examples in the IDE should help you with each of those. Then combine them.

But I would be familiar with the workings of each before attempting the combination.

If it should be a transparent proxy (so no changes to the PC side programs) I guess you will fail with the Arduino solution. This is possible with any cheap Linux router but too much for a device like an Arduino with an Ethernet shield. You simply do not have enough control over the TCP/IP features for such a project from the Arduino.

pylon:
The Arduino will not be flexible and probably also not fast enough to do so.

@pylon: You told him that. I told him that.
But don't you think it would be a great learning experience? :smiley:

SurferTim:
You should get a web server running, then a web client. The ethernet examples in the IDE should help you with each of those. Then combine them.

But I would be familiar with the workings of each before attempting the combination.

I think I should tryout this.

Pylon: apologies, I just went through a google search and realized what is the exact task of transparent proxy. I don't know exactly which proxy that I'm using on my project, (guess it's anonymous proxy) it forwards the packet by adding embedded system (arduino or what ever) IP address by hiding the source address (pc) and it should be able to block some main ports.

Here are a couple links that may help you out.

The first is a web server that partially parses the request.

The second is a client. It loads the Google home page every 10 seconds.

When you get a request from a client on the server, you will need to parse the request and call the client function to get the page from the destination server as a client, then send it to the server client as a server. :astonished: