-2

I have a crawler program that should run multiple threads each with a different IP address, about 10 threads simultaneously.

Is it possible to assign each thread a different IP address on a machine running Windows VII? With a Java program?

If so, can this be achieved by utilizing a machine that has multiple NICs?

I want to interface with these different IP addresses at the program level, is this feasible?

user207421
  • 305,947
  • 44
  • 307
  • 483
smatthewenglish
  • 2,831
  • 4
  • 36
  • 72
  • You should be able to assign each thread with the network interface. An each network interface should have different IP address. – rcs Jul 03 '14 at 08:30
  • Hi, is it possible you could please explain that a bit more explicitly? – smatthewenglish Jul 03 '14 at 09:27
  • It means nothing. Threads don't have IP addresses. Sockets do. @rcs needs to clarify his comment. – user207421 Jul 03 '14 at 09:28
  • @EJP: I am saying that network interface that has IP address, not the thread. The thread is used to do operation with the network interface. For example, we can declare a class that extends from class Thread, and inside this class we have class `Socket`. You may want to take a look at http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html. One of the constructor allows you to specify the IP address of the network interface you are going to use. `public Socket(InetAddress address, int port, InetAddress localAddr, int localPort)` – rcs Jul 03 '14 at 13:12
  • @rfs I'm aware of what the Socket documentation says. I've been reading it since 1997. What nobody was aware of was what your comment meant. You needed to clarify it. You don't need to patronise people who tell you so. It's the OP who has the programming problem, not me. – user207421 Aug 11 '14 at 00:19

2 Answers2

1
  • If your program uses Socket directly you can enumerate all the network interfaces and their IP addresses and use either bind() or the four-argument Socket constructor to bind to whichever local IP address you like.

  • If however you're using URLConnection I'm not aware you can specify a local address in any way.

  • I can't speak for HttpClient, but it has documentation you could consult.

  • If you're using something else, this tedious guessing game will continue until you deign to confide in us further as to what it is.

user207421
  • 305,947
  • 44
  • 307
  • 483
0

You can get the available nics by:

Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();

You can than use their InetAddresses to bind your threads to a specific nic.

Stefan
  • 12,108
  • 5
  • 47
  • 66
  • Would I need any special libraries or anything to do that? – smatthewenglish Jul 03 '14 at 09:05
  • You did not tell which technic you are using to connect. – Stefan Jul 03 '14 at 09:07
  • Maybe URL, Socket, ... For those you don't need additional libraries. – Stefan Jul 03 '14 at 09:17
  • I'm a research assistant, and they asked me to find out if this is possible, which is to say... what do you mean by connect? such as 'ssh'? – smatthewenglish Jul 03 '14 at 09:24
  • could you possibly point me in the direction of some kind of sample program/code snippet? – smatthewenglish Jul 03 '14 at 09:26
  • @user3787253 What do *you* mean by connect? What technology are you using? TCP sockets? URLConnections? HttpClient? Other? – user207421 Jul 03 '14 at 09:27
  • I mentioned three things and you did one of them, but it's irrelevant. Netsh isn't a connection technology. What are you planning to use to *connect to the target sites* and *download the data?* – user207421 Jul 03 '14 at 09:37
  • ah, some program we wrote, it's a crawler, it just goes around clicking links and whatnot – smatthewenglish Jul 03 '14 at 09:41
  • @user3787253 Come off it. *Answer the question.* That 'some program' uses (a) TCP sockets (b) URLConnection (c) HttpClient (d) other, and if (d) please state what it is. You've been asked this at least three times, complete with most or all of these alternatives. You won't get an answer by withholding information, or by ignoring what you're told or asked here, as you've done several times now. – user207421 Jul 03 '14 at 09:51