How to work with Ports on Webpage? - sockets

There are many programs written VB6 that use TCP ports.
Some of them listening, server out web pages, for example: 192.168.1.2:5352, when I go to this page, I see a page that allows me to control the VB6 program, This means there are some options that the programmer put on the page)
I want to know how to do this with my program listening on a TCP port (6006) and how to put some commands on a page, for example a textbox and button, so that when I enter something into the textbox on the page, my program displays in a message box.
Thank You!

It sounds like you're looking for an HTTP server component that you can embed in your application.
This can then serve out standard HTML pages that post data back to your app with a normal POST or GET request.
You can either do this with plain TCP sockets via the WinSock control and manually parsing the HTTP requests, or by using a service built into windows like the HTTP Server API but this is very difficult to use from native VB6.
Alternatively, you could loop at a plugin or CGI application with IIS or similar that communicates with your application via another method, maybe windows messages or named pipes.

Related

Can I access the source code of a PuTTY telnet server?

I'm sorry, I don't know how to phrase my question better.
For homework, I've been given a telnet server IP and Port that I connect to with PuTTY.
I was wondering if it is possible to view the source code of that server?
It is my first time learning about telnet and using PuTTY, and I don't know anything about it. I was just wondering if it is possible to view the source code of a telnet server, and if it is, how to do it.
Thanks.
I guess the idea behind this question is that if you're looking at a webpage you can do "view source" in the browser and look at the HTML, CSS, and Javascript that make up that page.
Of course, what you're seeing there is just the "client side" part of the web page. You can't click "view source" on Facebook and see the code that accesses their database, decides what to show in your feed, picks out the ads you're going see, etc., because that's all done server-side. Nor can you see the source code for the web server that handles your incoming connection, etc.
In the case of a telnet server, the "client side" portion is just the raw text you're seeing. There's nothing [1] analogous to what you'd see if you did "view source" in a browser beyond what you're already seeing in your telnet window.
Of course, if the program that they're running on the server side is publicly available, you may be able to download and read its source code. This is analogous to how, if a web site is running on apache or nginx, you can just download the source code for those and read them. But this is not something that's sent over the telnet connection.
[1] Slight nitpick: I guess technically if the text you're seeing has VT100 control sequences to highlight or colorize the text that is sort of analogous to HTML code, but it's very limited. If that's what you want to know about, you could either set your telnet client not to process those sequences in order to see what they look like, or you could capture the network traffic with something like tcpdump. But you can also just look up VT100 control sequences.

Use Webscarab to modify local html files in javaFX 2.2 through socket

I am able to load an html file in my webengine and sent the traffic through Webscarab with the following code :
System.setProperty("http.proxyHost", "localhost");
System.setProperty("http.proxyPort", "8008");
eng = view.getEngine();
eng.load("http://##########/");
The problem is that I want to load a local html page via the eng.loadContent(String htmlCode); method and again send the traffic through Webscarab. When I load the content into the webengine, the Webscarab is running but it does not seem to interfere the communication.
My goal is to achieve a communication through socket between a client and a server. The server which is a java program, run in the same machine as the Apache server, where i have my html and php pages. When the user makes a correct log in to the server, the server hits one of the pages to the local HTTP server and sends back to the client the source of the page as a string through the socket.
The next thing is webscarab to interfere before to load this content to the webengine and see the html page in the webview. After the changes to the code, I want to send the response from webengine to server, again through the socket.
To understand better what i want to do, below is the diagram of the architecture of my system.
Thanks in advance
When you load your page from html using loadContent() there is no traffic outside of JVM. You make a String, you put it into WebEngine and it parses that string. No proxy, no web, no sockets unless your page refers to some web resources.
As a workaround you may try to use separate engine to provide local html as sites. E.g. Jetty server. In a Jetty you can introduce a simple handler which return string you need, then give corresponding url to WebEngine.

Control a raw socket from a web interface

I have an microprocessor which I can control through a raw tcp socket. I can control the device through a desktop application, but I now want to be able to control it via the web. I've done lots of reading but I'm struggling to find the best method to do this. So far it seems creating a socket server in a webserver such as Tomcat or Jetty is the best option. When the user clicks a button the command is then sent to the micro processor. Is this a viable approach or are there better methods?
It is important that the system is very responsive, in other words, when the user clicks a button on the web page, the microprocessor must receive it as soon possible.
imo...separate your concerns
first write the code that implements the behavior you want with the microprocessor in such a way it is generally useful, and then plug on whatever sort of controller you want, be it web page, junit test, command line interface, whatever.

Confusion over Sockets and Ports

I am trying to write a programme that will 'listen' to application that is running on a port over TCP/IP.
When I point my browser to localhost:30003 , I get the output stream from the application printed to the screen. It would appear that the browser successfully 'listens' to the port.
What is happening here? Is my browser polling the application or is the application pushing tcp data which the browser picks up?
I am not sure whether to get this data I need to create a client or server instance.
One of the best ways to find out what is actually happening is to fire up Wireshark and follow the tcp stream.
http://www.wireshark.org/
Alternately, you can use something like TCP mon if you only care about the text, and none of the networking details.
http://ws.apache.org/commons/tcpmon/download.cgi
Based on the limited information in your question, the most likely thing is that the browser makes the tcp connection, and you send back a malformed response. The brower assumes you are a broken site, and does it's best to adjust. If you aren't sending the correct http header, it dosn't know what else to do so it probably just puts the text on the screen.
Best way to know the details is with wireshark or tcpmon
Pointing the browser to localhost:30003 will cause it the open the connection to port 30003 on the localhost and sent the string "GET /" to request a web page from what is thinks is a web host. Whatever text is sent by your app upon receiving a connection is simply displayed by the web browser as if it had received the contents of a text file on a web server.
when you write "localhost:30003" in your browser a connection is established to some program that listens to the port 30003 on your computer. The prefix in the URL, (default HTTP) determines the protocol used by server and client, in this case the browser is the client connecting to your PC, the server.
If you want to do the same with your program you can set up a socket connection to your localhost using the same port 30003. Your program then becomes the client. Depending on the program (which you don't mention anything about) you may have more protocol options and would need to handle the protocol in your program.
An alternative is to use telnet to connect to your program but it depends on available protocols.

See what website the user is visiting in a browser independent way

I am trying to build an application that can inform a user about website specific information whenever they are visiting a website that is present in my database. This must be done in a browser independent way so the user will always see the information when visiting a website (no matter what browser or other tool he or she is using to visit the website).
My first (partially successful) approach was by looking at the data packets using the System.Net.Sockets.Socket class etc. Unfortunately I discoverd that this approach only works when the user has administrator rights. And of course, that is not what I want. My goal is that the user can install one relatively simple program that can be used right away.
After this I went looking for alternatives and found a lot about WinPcap and some of it's .NET wrappers (did I tell you I am programming c# .NET already?). But with WinPcap I found out that this must be installed on the user's pc and there is nog way to just reference some dll files and code away. I already looked at including WinPcap as a prerequisite in my installer but that is also to cumbersome.
Well, long story short. I want to know in my application what website my user is visiting at the moment it is happening. I think it must be done by looking at the data packets of the network but can't find a good solution for this. My application is build in C# .NET (4.0).
You could use Fiddler to monitor Internet traffic.
It is
a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. Fiddler allows you to inspect traffic, set breakpoints, and "fiddle" with incoming or outgoing data. Fiddler includes a powerful event-based scripting subsystem, and can be extended using any .NET language.
It's scriptable and can be readily used from .NET.
One simple idea: Instead of monitoring the traffic directly, what about installing a browser extension that sends you the current url of the page. Then you can check if that url is in your database and optionally show the user a message using the browser extension.
This is how extensions like Invisible Hand work... It scans the current page and sends relevant data back to the server for processing. If it finds anything, it uses the browser extension framework to communicate those results back to the user. (Using an alert, or a bar across the top of the window, etc.)
for a good start, wireshark will do what you want.
you can specify a filter to isolate and view http streams.
best part is wireshark is open source, and built opon another program api, winpcap which is open source.
I'm guessing this is what you want.
capture network data off the wire
view the tcp traffic of a computer, isolate and save(in part or in hole) http data.
store information about the http connections
number 1 there is easy, you can google for a winpcap tutorial, or just use some of their sample programs to capture the data.
I recomend you study up on the pcap file format, everything with winpcap uses this basic format and its structers.
now you have to learn how to take a tcp stream and turn it into a solid data stream without curoption, or disorginized parts. (sorry for the spelling)
again, a very good example can be found in the wireshark source code.
then with your data stream, you can simple read the http format, and html data, or what ever your dealing with.
Hope that helps
If the user is cooperating, you could have them set their browser(s) to use a proxy service you provide. This would intercept all web traffic, do whatever you want with it (look up in your database, notify the user, etc), and then pass it on to the original location. Run the proxy on the local system, or on a remote system if that fits your case better.
If the user is not cooperating, or you don't want to make them change their browser settings, you could use one of the packet sniffing solutions, such as fiddler.
A simple stright forward way is to change the comupter DNS to point to your application.
this will cause all DNS traffic to pass though your app which can be sniffed and then redirected to the real DNS server.
it will also save you the hussel of filtering out emule/torrent traffic as it normally work with pure IP address (which also might be a problem as it can be circumvented by using IP address to browse).
-How to change windows DNS Servers
-DNS resolver
Another simple way is to configure (programmaticly) the browsers proxy to pass through your server this will make your life easier but will be more obvious to users.
How to create a simple proxy in C#?