PDA

View Full Version : Changing IP adress with java?



jspolen
April 5th, 2009, 12:21 AM
Hi wondering if it's possible to send a string or whatever from a client class to a server class, but with a different ipnumber that I'm currently using.

So when I retrieve the ip from the client on my server it says something like 111.222.333.444.




import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.Socket;

public class SimpleClientMain
{
public static void main(String[] args)
{
try
{
Socket socket = new Socket("127.0.0.1", 80);

//Change my ip number?????

DataOutputStream writer = new DataOutputStream(socket.getOutputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));

writer.writeBytes("Hello!\n");
String fromServer = reader.readLine();

System.out.println(fromServer);

socket.close();
}
catch(Exception e)
{
e.printStackTrace();
}

}
}

dwhitney67
April 5th, 2009, 01:01 AM
You would need to create a raw socket, in which you would setup the IP and the TCP (or UDP) header.

I have not tried this with TCP, but I have done so with UDP. As for doing it in Java, I do not know if this is possible.

If it is possible, you (or I should say your application) will require root-privileges to create a raw socket.

jspolen
April 5th, 2009, 01:28 AM
ok I will look into that
thanks

myrtle1908
April 5th, 2009, 02:01 AM
I recall a library named RawSock or SockRaw or something ... can't quite remember.

Edit: Here it is ... RockSaw ... http://www.savarese.org/software/rocksaw/index.html

Arndt
April 5th, 2009, 09:26 AM
You would need to create a raw socket, in which you would setup the IP and the TCP (or UDP) header.

I have not tried this with TCP, but I have done so with UDP. As for doing it in Java, I do not know if this is possible.

If it is possible, you (or I should say your application) will require root-privileges to create a raw socket.

To create a new socket as such shouldn't require root privileges, but for low port numbers, such as port 80, it usually does. This is why you often see ports like 8000 or 8080.

dwhitney67
April 5th, 2009, 12:24 PM
To create a new socket as such shouldn't require root privileges,...

oh, but it does... that is, for raw-sockets. For regular sockets, root-privileges may not be required.


but for low port numbers, such as port 80, it usually does. This is why you often see ports like 8000 or 8080.
If a port number is above 1023, then root privileges are not required. The max port number allowed is 65535 (2^16 -1).


P.S. It does not matter if the language is Java, C, C++, or even python... for socket creation/usage, the high level language will ultimately interface with the underlying kernel and this is where the user's permission level and the parameters used to create the socket are examined.

Arndt
April 5th, 2009, 12:45 PM
oh, but it does... that is, for raw-sockets. For regular sockets, root-privileges may not be required.


I see; sorry for the misinformation.