Make private computer's IP accessible by server using Java - java

To say in other words: My computer has an IP address 1.1.1.1 and the server has an IP address 2.2.2.2. My computer can access the server's IP 2.2.2.2 and work with services running on its ports (Apache, SOCKS proxy etc.). But the server can't do the same with my computer - my ISP doesn't allow it - it means when I run an Apache service on my computer on port 80, the server isn't able to call 1.1.1.1:80 (the call won't pass ISP's firewalls and reach my computer).
So, is there a way (but not contacting the ISP) to allow the server to call my IP address with successful response?
I will need some Java code to do that.
I mean creating some sort of "tunnel" which my computer opens to the server and makes the computer's IP accessible through the tunnel.

Related

Java Server client and hos name computer

I made a simple java client server program its work very well on my computer (localhost) but when I run the server on my computer and the client on friend computer I don't know how to get my full hostname that the client need when I go to system information get the hostname from their and run the client he cant find this hostname, what I supposed to do thank you for your help
Sounds like what you want is port forwarding.
Login to your router by going to 192.168.1.1 on your web browser (if that doesn't work try 10.0.0.1)
Type in your username and password for the router, they're usually on a sticker on the side of the router.
Get your computer's local IP address by looking for your computer's name in the list of connected hosts on the router, or by following the instructions for your OS on https://kb.iu.edu/d/aapa
Go to the port forwarding section on your router's config page and add a new rule that forwards traffic from the port you specified in your program (like 5000 or something like that) to your local IP address (something like 192.168.1.12).
Get your public IP address from https://whatismyip.com
Make your client program try to connect to your public IP on the port you chose
Start your server on your computer that you port forwarded
You should then be able to tell your friend to start his client to connect to your server.

Getting Connectiontimedout error when creating a remote SocketServer in Java

In the socket programming i am able to connect to the server socket when it is on the same pc i.e 127.0.0.1 but when my friend at a remote location runs the server program and i try to connect to it it shows the Connectiontimedout Error.
I'm giving the ip address and port number right.
Do i need to add something extra?
In order to access server remotely, your friend should bind the server to an IP address which is accessible from your machine. This will not be the case if your friend's ISP or wifi router has allocated a private IP address to him.
In such case both of you can join a Virtual Private Network to be on the same network.
Another option is port forwarding. If both of you can access a common machine then your friend can forward a port from the common machine to the application server's port to his machine. Now you can access your friends application server by accessing the socket at forwarded port on common machine.
If both of you are already on the same network then it might be possible that the server is listening on 127.0.0.1 interface only.
There are possibly other middle-boxes that do NAT (Network Address Translation) in the path between you and your friend. These normally prevent the initiation of TCP or other connections over the Internet.
Try doing the same with both of you on the same LAN (Local Area Network) or with a Hamachi VPN to simulate a LAN over the Internet.
Another possibility is configuring your router/NAT at your location to forward the port for your application to the IP address of your machine. In this case make sure to give your friend your public IP (you can get that with http://checkip.dyndns.org/).

Connect via TCP and public IP without forwarding

I'm trying to write a simple chat program using TCP in java.
To connect to a server I need to know its IP address. I'm connected to a router in my network, that connects me to the Internet.
When I type local IP (assigned by router) it works pretty well between my two computers.
But when I typed public IP (I got it from google: "what is your ip"...) - it didn't work.
So I opened router's setup and make forwarding rule from my public IP and specific port to the local IP - and it worked.
--------- Question:
But how to do this without forwarding? I want to write a chat program. I can't tell my users: "just do the port forwarding" ;)
One opens my program and logs into central server, then writes there public IP. Some other user opens this server, download the file and gets first user's IP (or any other needed info).
But if first user didn't do the port forwarding, it won't work. How to make it work?
For this you will need to understand how something called NAT (network address translation) works. In simple terms the NAT is responsible for sending packets to the right computer on the internal network from the external.
Say for example you have computer A as a server on the internal network, and have computer B on the external. If you then try to connect to computer A from computer B, it will not work because NAT (your router) doesent know what computer to send that packet of data to, on the internal network.
Its diffrent when you want to connect to an external server. Lets say computer A (client) is on the external network, and computer B (server) is on the internal network with the router port forwarded to its IP-address. Then you will be able to connect to the server because NAT knows where to send the data packets.
So to keep all your users from port forwarding their routers:
Port forward your server on your internal network
Connect the clients on another network
For clients on the internal network; use the local IP of the server
Hope this helped!
-Kad

How can I change IP in HttpServletRequest from client side?

server code:
String ip = request.getRemoteAddr()
if(ip='127.0.0.1')
System.out.print("hello");
Now I am accessing that remote site from my machine, so obvious my IP address should be like 192.*.*.*.
How can I cheat the server(IP spoofing) so server always prints "hello" for my request?
New answer to edited question:
You can't in Java. If need to pretend that the request is coming from 127.0.0.1 (the server itself), so you'll need to hack into the network stack of your operating system.
Old answer:
The IP Address your client uses to connect to the server depends on the network interface it uses and the kind of network attached to this network interface.
Example:
If your client is a laptop it most likely has only one network interface. This network interface uses 192.168.1.10 as its IP address (e.g., assigned from the DHCP on your router) as its internal IP address. Your router might also be connected to the internet, with an IP, say 20.20.20.20, which it shares with connected devices via NAT.
If you use this to connect to your server which is on your local network, the client's IP address that the server sees will be 192.168.1.10; if you connect to your server which is not on your local network but somewhere on the internet, your client's IP (that the server sees) will be 20.20.20.20
So you cannot make your client pretend to use 127.0.0.1 (if server and client are running on the same machine, your client will most likely have 127.0.0.1). Of course there are techniques like IP spoofing where you pretend to have a different IP than you actually have, but that's totally different issue.

How to give access to localhost:8080 on network?

How to make my computer as a server so I run the application on IDE and be accessible by other computers on same network via their browsers?
If your server local ip for example is 192.168.1.20 and your web server port is 8080 then you can access your server by giving IP:PORT in the browser
eg: 192.168.1.20:8080/index.jsp
You can't make "localhost" accessible, by definition. What you can do instead is have the server process listen on an external IP address (or all addresses) instead of just on the loopback address. We can provide a more specific answer if you'll tell us how you're launching the application server.

Categories