Get URL from Socket | Telit Cinterion IoT Developer Community
December 2, 2016 - 5:28pm, 2505 views
Hello!
I have built an app with BGS5T which handles HTTP requests to manage an equipment. This is working pretty well but now I'm developing security measures for the system.
In the following code, I create a socket with my network profile, socket that will handle my requests from the website:
server = (ServerSocketConnection) Connector.open("socket://:" + portoX + ";bearer_type=GPRS;access_point=" + APNX + ";username="+ LoginX + ";password=" + PasswordX + ";dns_value=" + DNSX+ ";timeout=0");
SocketConnection sc = (SocketConnection) server.acceptAndOpen();
When the connection is accepted,
I open an inputstream,
is = openInputStream();
and read the content in that said stream to keep the http request and manipulate it.
The only thing that I'm being able to keep is the IP of the website using the getAdress() method and the header of the http request.
Example:
"GET /api.html?ATCOMMAND=AT^....."
The thing is that I would like to get the URL from the client trying to connect to the modem. This would allow me to block undesired connections from other websites. I'm already doing this by IP, but I'm afraid that the website IP might change.
Since we're stuck to j2me library, I can't use tools that would make the task easier.
Any suggestions?
Thanks
Hello,
You are talking probably about the reverse DNS lookup. Please try this method: com.cinterion.misc.NetExtension.HostbyAddr(String Hostaddr).
In fact when some host connects to your server it connects from the certain IP not the domain and you are able to read this IP.
The domain address is used when you connect to to some server - it is translated by a DNS server to the IP and then you connect to the IP again. There may be many domains on the single IP.
Regards,
Bartłomiej