Forwarding Data Passed From a WebSocket - java

I have set up a websocket between an android application of mine and a tomcat server that is hosted online. My app is supposed to be able to give an IP address and port number of an outside website and use the websocket to contniuasly forward data to the server which will then pass it on and retrieve from whatever this outside website the user specified is.
So my question is, is there a way to pass in the ip address and port number in my request to create a websocket that will tell my server to forward it on to the given IP address?
I hope this all makes sense, I'm still trying to wrap my mind around it myself so let me know if there is something I can explain better.

Related

Same public ip address is returned in java

In my project I need to find the public ip address of a machine.
I have implemented that using method mentioned in Finding public ip address using java
I have an api url like 'http://182.14.10.5:8080/test/addVendor' (not exact url) in my project and has been deployed in external tomcat server which has public ip address as 187.15.161.90.
The issue am facing is:
When i tried loading this api url from other devices like mobile or computers belong to some other network, am getting the same ip 182.14.161.90 for every URL hit.
This is where i got confused. Whether the program is written according to that or am i getting wrong output.
According to the search results what I understood is, when I load the particular api url, I should get different ip address based on different machine connected with different network.
But am getting the same public ip (182.14.161.90) of the server where my project is deployed.
Can anyone pls clarify it and help me to fix the issue.
Any suggestions would be appreciated.
Thanks
It sounds to me like you have a Java Web Application deployed via tomcat and want to get a user's IP address.
The question you've linked in your question Finding public ip address using java is specifically for getting the IP address of the machine where the Java Code is running (for example, if you have a desktop application and want to get the IP of the machine that app is running on for some reason)
If you want to get the user's remote IP, it depends on your server configuration
If Tomcat is the ONLY webserver in your environment, and there is nothing in front of it, you can access the Request's remote ip using HttpServletRequest#getRomoteAddr, which will give you the IP address of the socket connection that initiated the Request.
This will work great unless you have a proxy server, like Apache HTTPD or Nginx in front of Tomcat, in which case you'll need to configure your server to send the
X-Forwarded-For header, and get the user's remote IP using HttpServletRequest#getHeader for example, request.getHeader("X-Forwarded-For")
If I've misunderstood your question, please clarify and let me know with a comment.

Submit server IP from wifi router to Android

I'm currently writing an app that's to connect to a server over a wireless lan.
So far, I've got the IP address hardcoded into the app (which works perfectly), however, the next logical step is to be able to send the app the server IP address.
From what I understand, the router needs to broadcast the IP address over 255.255.255.255 - apart from that, I have no idea what to do.
Any and all help is greatly appreciated
edit
ok, so I know to get this working, all phones have to be on the same network as the server, which is fine.
What I need to do is get the phone to broadcast on the network whilst my server listens. From there, the server sends the app its IP address, then the rest of the code can continue.
Does anyone have a tutorial or anything I can follow to get both sides working?
one simple solution for you not to hardcode the server's IP or name (let us say it changes over time), would be for you to implement a name server on your network and have the android device call a local URL.
you could then post the current server's IP or name in the header of a web page on your local network. this response would then be used by android app.

How to get the Node's server IP behind a load balancer in Java

I have a webpage behind a load balancer, and I want to display the user (for troubleshooting purposes) the IP of the actual node that the user is connected to (will be the same for a while due to sticky session)
I'm sure it's a very trivial question, but I want to be sure, what Java API should be used for that? will all APIs return me the request host? or will it be server dependent?
InetAddress.getLocalHost().getHostName() will give you the name of the server you are on.
InetAddress.getLocalHost().getHostAddress() will give the IP Address of the server you are on.

Using Clients IP as the Servers IP

This might be one of those "huh, why?" questions, but I figured it would be worth the try.
How would one, from a server-side application, use the clients IP address as the applications IP address to another website? The basic idea is that any work the server side application does, is seen as the client itself doing the work, and not the servers static IP.
I am not sure if changing HTTP headers would work, but I could be wrong. Is there any documentation out there on this?
Thanks,
Kyle
Utterly, utterly impossible. You won't even be able to open a TCP connection because the other website's server will try to handshake with the client, and fail.
An IP address isn't just any old ID, it's the actually address that servers will send any response to. Spoofing it basically only makes sense if you can fit your request into a single IP packet (which rules out TCP and thus HTTP) and are not interested in the response. Even then it can fail because your ISP's routers may have anti-spoofing rules that drop packets with "outside" IP addresses originating from "inside" networks.
Why on earth would a legitimate application want to spoof its IP address?
Changing HTTP headers might cut it, but most likely it won't. Depends on how naive the other server is.
It sounds like you're trying to do something the wrong way, can you give a bit more information as to what exactly the use-case is?
If there's no processing to be done in between, you can do port forwarding on your server's IP firewall, so the client connects to your server but ends up talking to the other server.
If there's more involvement of your server, then the correct thing to do would be to pass the client's IP to the other server as part of the URL (if it's a web app) or elsewhere in the data (if not) so the receiving server can know and correctly log the process without any need for fakery. Of course this would also call for a change in the other app.
Again assuming we're talking about HTTP, another idea that came to my mind would be to redirect your client to the other server. As long as all necessary data is in the URI, you could advise the client's browser to connect to the other server with a URI of your own creation that could carry whatever extra value your server's processing adds to the request.
Decades ago, the designer of internet asked, "how can we prevent Kyle Rozendo from doing such a devious thing?"
If the client is cooperating, you can install some software on client machine, and do the work from there. For example, a signed java applet on your page. [kidding]If the client is not cooperating, install some trojan virus[/kidding]

Using java applet to send request with the client ip

i need to send a request to a website when a user submits their url, i tried using curl but it uses server ip which i dont want i have seen a website that is doing a similar job by using applet, users need to open a popup which contains the applet after they leave it open allow it to run it uses a port and then uses the localhost ip like so 127.0.0.1:64653 to send request and basicly curl by the user ip. i decompiled the applet the website was using and they were using java.net.ServerSocket and some other java code but i do not know anything about java. I would to know how this can be done.
I think you are really confused.
a user does not have a URL.
there is a IP address that
represents the browser end of the
connection to the web server he/she
is connected to (actually, there
could be more than one) but this
does not allow something else to
establish a connection to the
browser. So it is not a URL.
the IP address + port number
that the browser has are transient.
In 2 minutes time, the very same
IP/port could denote a different
user, possibly even on a different
machine.
127.0.0.1 is a "special" IP
address that says "this machine".
It cannot be used for communication
with another machine.
notwithstanding all of the
above, web browsers do not accept
incoming HTTP connections from web
servers or anything else. The HTTP
protocol (which is what the web
works on) distinguishes between the
roles of "client" and "server", and
specifies that a client connects to
a server and not the other way
round. A web browser is always an
HTTP client, by convention and also
for security reasons.
So when you say ...
i need to send a request to a website when a user submits their url
... it simply does not make any sense. Please explain what you are tying to achieve ... not how you are trying to achieve it ... and we might be able to help.

Categories

Resources