How to send HTTP Commands through Port 80 - sockets

Breif Description of what I am trying to accomplish. So I am working with Crestrons Simpl+ software. My job is to create a module for a sound masking system called QT Pro. Now, QT Pro has an API where you can control it via HTTP. I need a way to establish a connection with the QT Pro via HTTP( I have everything I need, IP, Username, Password).
Whats the problem? I have just started working with this language. Unfortunately there isn't as much documentation as I would like, otherwise I wouldn't be here. I know I need to create a socket connection via TCP on port 80. I just don't know what I'm supposed to send through it.
Here is an example:
http://username:password#address/cmd.htm?cmd=setOneZoneData&ZN=Value&mD=Value
&mN=Value&auxA=Value&auxB=Value&autoR=Value
If I were to put this into the URL box, and fill it in correctly. then it would change the values that I specify. Am I supposed to send the entire thing? Or just after cmd.htm? Or is there some other way I'm supposed to send data? I'd like to stay away from the TCP/IP Module so I can keep this all within the same module.
Thanks.

You send
GET /cmd.htm?cmd=setOneZoneData&ZN=Value&mD=Value&mN=Value&auxA=Value&auxB=Value&autoR=Value HTTP/1.1
Host: address
Connection: close
(End with a couple of newlines.)
If you need to use HTTP basic authentication, then also include a header like
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
where the gibberish is the base64-encoded version of username:password.
But surely there is some mechanism for opening HTTP connections already there for you? Just blindly throwing out headers like this and hoping the response is what you expect is not robust, to say the least.
To see what is going on with your requests and responses, a great tool is netcat (or telnet, for that matter.)
Do nc address 80 to connect to server address on port 80, then paste your HTTP request:
GET /cmd.htm HTTP/1.1
Host: address
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Connection: close
and see what comes back. SOMETHING should come back. (Remember to terminate with two newlines.)
To see what requests your browser is sending when you do something that works, you can listen like this: nc -l -p 8080.
Then direct your browser to localhost:8080 with the rest of the URL as before, and you'll see the request that was sent. (Then you can type back to see how the browser handles the response.)

Related

Fiddler can't track the traffic but httpAnalyzer can (connection looks like websockets)

I need to explore the traffic from one program.
The program makes something like a connection through the WebSockets.
Fiddler displays this:
Request Headers: CONNECT 144.***:443 HTTP/1.0
Response: HTTP/1.0 200 Connection Established
End empty body.
But the HTTP analyzer displays full information after that response, and that information continues flowing. Very likely like WebSockets (one connection and receive more answers).
And fiddler display zero traffic.
How can I explore such traffic through the fiddler?
A CONNECT call is always the first command a client sends if it uses a Proxy. Translated CONNECT just means: Please start a connection to the following server and that port. Through that connection the real HTP calls are then transmitted. Therefore CONNECT is not a real HTTP
request.
Fiddler does not show the content of CONNECT requests/responses to port 443 endpoints because those connections are HTTPS/TLS protected (hence the shown data would be useless). You need to enable HTTPS decryption and install the Fiddler root CA certificate into the client app/OS to see the decrypted content of those connections.

cURL'ing a Phoenix socket

Is there a way to curl (or something similar) a phoenix socket?
Let's say my server is running on localhost:4000, and my endpoint has:
defmodule MyApp.Endpoint do
use Phoenix.Endpoint, otp_app: :my_app
socket "/socket", MyApp.UserSocket
I have a UserSocket module with a connect method. What can I run from the command line to connect to this socket?
cURL supports by default long polling. You don't have to add any flags, just hit websocket url but you have to use http(s) not ws(s) protocol in url. Don't forget to add Accept and content type headers as application/json.
There is one drawback. You can't POST message to same connection :) so I guess it is better to use telnet instead and code by hand header to initiate polling so you can send (post) messages from same console. this way you can debug if "socket" is returning ok reply for your client pushes. and what is event better with this approach you can actually use HTTP 101 protocol upgrade to ws(s) :)

Printer suddenly starts and prints message from libwww-perl

We have a network printer that will suddenly fire up and print five lines (three times this month)
GET / HTTP/1.1
TE: deflate, gzip;q=0.03
Connection: TE, close
Host : <printer IP>:9100
User-Agent: libwww-perl/6.13
I'm guessing that something is scanning ports, but don't know where it's coming from - it only identifies the printer IP address. The network is all cable, no Wi-Fi enabled...
Any idea what could be doing this, and how it can it be located?
The printer is an old (probably 15 years at least) HP Colour LaserJet 4500N with it's own network card and will reply to a ping request from anywhere on the internet...
Thanks
It seems like some automated Perl script is trying to access the printer's web console. The User-Agent line tells the request comes from LWP, the most commonly used library to make web requests from Perl.
As you just found out, similar behavior can be invoked by just entering http://<printerIP>:9100 in a web browser. Now it is only a matter of tracking down the visitor. You may find a log in the management console that gives you the visitor's IP address.

Is it possible to make a relay agent (application layer) of a server (service)? Any example? C will be better

I'm trying everything to NAT traversal to make a HTTP(or others) server be accessible from internet.
this is the previous question but with no luck.
HTTP Server behind NATs
So I'm trying to do the following
IE <--> agentC <---------NAT/Internet/.....----------->agentS<------->Apache Server
the scenario might be...
1.User input address in IE like "localhost:9999" (agentC)
2.agentC connect with agentS with Stun/TURN/ICE
3.agentS relay data to Apache Server and then reply to client.
I also refer to the following:
Is it possible to 'relay' a socket?
but the problem is:
1.the connection between agentC to agentS might be UDP, however the Http is on TCP, is it possible to "relay socket or packet"
2.I'm coding test code of agentS<---->Apache part,
((pp = popen("echo -e \"GET / HTTP/1.0\\n\\n\\n\"| nc localhost 80", "r")) == NULL)
.........
But the out put always "400 Bad Request".
(while type "echo -e "GET / HTTP/1.0\n\n\n"| nc localhost 80" in console will be successful)
3.I will modify a simple console chatroom to be agentS and agentC, is it possible to carry the http data (like pic,download...etc)?
Thank you for your patience
You don't really relay the socket, instead you relay the data. For example, "agentS" in your example opens a listening socket where it accepts connections from "agentC". When it gets a new connection from "agentC" then "agentS" connects to the web-server and enters a loop where where all it reads from either connection ("agentC" or web server) is sent to the other connection.
Since the two connections are independent it doesn't matter if one is TCP and the other UDP.
Also, if you need to do some processing on the data in "agentS" it's easy, as you actually have the data. The protocol between "agentC" and "agentS" doesn't even have to be HTTP, it can be whatever you want, as the programs can do protocol translation.
As a side note, when sending data to a web-server you end the lines with "\r\n", and the header is terminated by a single "\r\n" on its own line. So you only need to send "\r\n\r\n" after the GET request.

How do online port checkers work?

For example http://www.utorrent.com/testport?port=12345
How does this work? Can the server side script attempt to open a socket?
There are many ways of accomplishing this through server-side scripting. As #Oded mentioned, most server-side handlers are capable of initiating socket connections on arbitrary ports, and most of those even have dedicated port-scanning packages/libraries (PHP has one in the PEAR repository, Python's 'socket' module makes this type of tasks a breeze, etc...)
Keep in mind that on shared host platforms, socket connections are typically disabled for security purposes.
Another way that is also very easy to accomplish is to use a command-line port-scanner such as nmap from your server-side script. i.e in PHP, you would do echo ``nmap -p $port $ip\
The server side script will try to open a connection on the specified port to the originating IP.
If there is no response (the attempt will timeout), this would be an indication that the port is not open.
The server can try, as #Oded said. But that doesn't ensure the receiver will respond.
Typically, something like this happens:
The URL request contains instructions about which port to access. The headers that your browser sends include information about where the request is originating from.
Before responding to the request, the server tries to open a port and checks if this is successful. It waits a while before timing out.
The webpage is rendered dynamically based on the results of this test.
The response is returned to you containing the results.
Sometimes steps (2) and (3) will be replaced with an AJAX callback, which allows the response to return sooner.