I want to run Linux command remotely from Window based Qt C++ application programmatically. What is the simpliest way to do it?
You need some sort of server on the Linux machine and your Windows machine will be a client. I'd say the easiest way would be just make a php script to run your command and drop it in your www root and have your Windows machine fetch that URL.
At the end of the day, without knowing what your requirements are with regard to security and with regard to what kind of commands you'll be running is, it's very difficult to give a definitive answer to this question.
Simply connect to telnet server on the linux using sockets, and send the commands.
This actually requires very little code. Check the Java version here:
Sending telnet commands and reading the response with Java
You can do similarly with Qt/C++ as well.
Simple server-side program witch will handle the requests and then using ex system() function will be this "remotely" part of solution.
And on client-side simple text field handled by function witch will be able to connect to server to send command run request.
The most important thing in this solution will be to take care about security.
One way to do it is, to have a client-server model, the server resides in linux and client can be your computer. That way you can send commands to the server and have its output thrown at you. That's one way I think of this problem.
Use UPnP to get past the firewall(or use NAT traversal or UDP/TCP hole punching). Otherwise (without forwarding the port) it would be impossible to reach the server.
The second is to write your own RSH and SSH utility. (or use putty or other pre-existing software)
You could use Plink if you are on Windows whatever version. If you can run PuTTY, then you can run PLink. PuTTY Plink Documentation. Using that you could use the executable, and automate things. Otherwise, if you're looking for a specific programming language, they'd still be dependent upon some SSH Library. If you're writing your own installer, you could include the PLink.exe in your installer, and distribute it with your application.
From the documentation page:
Z:\sysosd>plink login.example.com 'echo "Hello World"'
Related
I am writing an application to run on a robot. Currently, it is headless, but I want to be able to telnet directly to the application with no authentication and access a shell that I will write.
Is this possible? Would it be practical or are there much easier solutions?
It is entirely possible.
However, if you are using Linux, you may just as well just let your application do it's I/O to the terminal, and use telnet to log in. If you set up a user to use your application as the "login-shell", it will allow direct access to that user called "robot" (for example) (and you can set it to have no password too) - then just do telnet -l robot machine port.
This would save you the effort of writing your own telnet client, and give you almost identical functionality.
If you're using a custom shell, why would you need telnet? Your shell can have a daemon component to listen on given port and then hand over the interaction to whatever REPL your shell would implement.
Some Background -
I have written a C program on the TS-7800 (running Debian Linux) which I access through Putty. The program is essentially in charge of controlling DAC/ADC's in order to modify the state of a memory element.
My next task is to develop a GUI for that program. The GUI is built using Microsoft Visual Studio 2010 in C++. I've made most of the GUI and simply need a way to send the data which I collect to the Linux machine.
My first attempt was to invoke a connection with Putty through command line from the GUI, and then try to send various commands through that Putty connection. The drawback here is that once I invoke a connection with Putty using the command putty username#192.168.1.50, it is done in the foreground, rather then hidden in the background, and I don't know how to continue entering text/commands from the GUI into Putty once it has been launched.
My Question -
How should I go about connecting my GUI on Windows to the program on the Linux machine? Is my attempt with Putty a step in the right direction, or should I be taking a different approach - possibly Cygwin?
Thank you in advance for any help - this is my first post on stackoverflow so please forgive me if I've mistakenly overlooked some detail or if I did not abide by proper etiquette.
You have to follow some protocol to interact with the server. Then your GUI needs to follow that protocol to send commands to the server.
Probably, you are talking about SSH connection with server. There are a lots of SSH Client library available in windows. You can use one in your GUI to interact.
Try taking a look at Boost ASIO. It's a very solid asynchronous IO library included in boost. (You will need to build it however).
I am developing an application in ubuntu to access the other system remotely through QT. Both system are running some Qt applications.I want to check / make changes to the other system remotely using Qt programming.
I want to add a pushbutton (as a quit screen) at remote system that should be "Enable only if the system is remotely accessed", so that i can use it to close the remote access screen.
Is there any way through programming we can get the status whenvever it is remotely accessed???
I got through some solutions on forum but they are particularly for Windows. I am looking for some solution in Linux.
Please provide suggestion/links so that i can overcome this issue.
Thanks in Advance
If you are using the remote display abilities of the X11 protocol, you could check the value of the DISPLAY variable. For a local connection, it usually starts with :0; for a distant connection, it contains the hostname of the displaying server. For a connection thru ssh -X it could be localhost:10 and ssh is also setting SSH_CLIENT and SSH_CONNECTION environment variables.
Otherwise, you should define better what is a remote access for you (i.e. explain more your application). Your Qt application may also be e.g. some TCP/IP server. Perhaps the getpeername(2) syscall might be relevant.
If you just are interested in what remote connections flow into your box (independently of a particular application) you could read (e.g. using popen) the output of command netstat -a -n or use some /proc/net/ directory.
I am new to Django and i was wondering if i can do some backend testing using Django. I have already installed Django in windows. My work usually deals with putty(e.g. opening files, checking some data in a file, but this all is done in a putty box). So i was hoping if somehow i can take all the work from backend to front end by accessing putty from django(e.g creating a link to start a putty session, logging in and performing some operations). Please help me in providing the information if this can be done and if its possible, how to do it.
Thanks in advance,
For a start, you need to learn the difference between putty (a Windows application that emulates a remote terminal) and ssh, a protocol for logging into remote systems. So, if you want to do something remotely via Python, you should be thinking about how to start an SSH session, rather than how to automate putty particularly. You might, for example, look into the paramiko library, which does just that.
Secondly, as the other answerers have mentioned, this seems an odd requirement. Web frameworks are not ideally suited to doing things like this. If you just want to automate some remote operations, perhaps fabric is what you need.
Since putty is a different application you need to spawn a subprocess and communicate with the application through stdin and stdout. This can be done using the subprocess module.
But please remenber, that Django is a web framework. This means it is for creating web application. Your problem looks more like a general "I want to automate something" problem where you don't need a web framework - you can simply use pure python. Is there any reason why you are using Django?
What can be done to know and list all running processes on a remote computer?
One idea is to have a server listening to our request on the remote machine and the other one is to use ssh.
The problem is i dont know whether there will be such a server running on the remote machine and i cannot use ssh because it needs authentication.
Is there any other way out ?
If you
cannot install a server program on the remote machine
cannot use anything that requires authentication
then you should not be allowed to know the list of all running processes on a machine. That request would be a security nightmare!
You can do something much simpler without (as many) security problems: scan the publicly-available ports for programs that are running. Programs like nmap.org let you know a fair bit of information about the publicly-running programs on machines.
I have done something similar in the past using SNMP. I don't have the specifics in front of me, but something like "snmpwalk -v2 -c public hostname prTable" got me the process table. I recall later configuring SNMP to generate errors when the number of processes didn't meet our specified requirement, like httpd must have at least 1 and less than 50.
I suggest you look at the code for a remote login, rlogin. You could remotely login to an account that has the privileges that you need. Once logged in, you can fetch a list of processes.
This looks like a good application for a script rather than a C or C++ program.