Open plink as default shell in conemu - conemu

To connect to remote servers I use putty inside conemu which does not allow splitted consoles.
Then I used plink.exe in conemu, got the split screens but pressing ^c two or more times returns back to command prompt (in putty the remote system is still connected).
I was wondering if there is a way around this, all I need is to use splitted screens to connect to remote systems and remain connected even if ^c is pressed.
I am trying to split screen and run plink as defualt shell in the newly spllited window, so far no luck.

Related

C : how to to execute remotely a command line programm and interact with it from a server?

I made a simple tcp client in C (in windows I precise), which is controlled by netcat. I would like to be able to run a command line executable (such as Strings for example) remotely, and above all to be able to interact from netcat or my server with this programme.( (in order to perform actions on the remote computer in particular).
What would be the best solution to do that ?
edit : Here is an example : I want to run String programm on the remote computer. To do that, I can simply write "string" in netcat, this command would be interpreted by client, and this client execute strings binary. The output of strings should be displayed on netcat.
I precise that the binary of the programm can be on the remote computer, but it would be great if there is a way to execute it as a "real" remote programm, without need to get the executable on the remote machine.
First of all, your terminology is a bit off. You said you write a tcp client. But it seems you wrote a server. Because this programs should receive incoming tcp connection and request to then send responses.
In order to execute commands, you can use the exec* syscalls.
But then you would need to have the executables available in the machine.
Then you would need to build some for for loop around the tcp read that execute things for each line send, and a bit of setup to ensure that you redirect the output in the tcp connection. See the dupsyscall.
Ultimately, if you do not want to write a full shell-like program, you could just execthe system shell (cmd.exe on windows I think), and redirect all inputs/output to it.

Batch server ping and restart for a game

Just looking for a correction/addition to this cannibalized restart code for (originally a Minecraft server, though that is not what it's used for now).
#echo off
title Server Restarter
color 0A
cls
#%SystemRoot%\system32\ping.exe -n 1 xxx.xxx.x.xx
pause
:start
Call Server.bat
cls
pause
This currently does a very simple job: calls server.bat and starts the server. It has none of the bells and whistles I'd like it to have though.
The output of ping is not functional at the moment.
The goal:
Ping to see if a specific IP (and maybe ports) are reachable.
If they are not reachable, close any current instances of Server.exe
Continue pinging until specific IP is reachable.
Once the IP is reachable, call server.bat
It needs to ping at intervals of ~30 seconds.
Some context for why it's needed:
The game server does not currently close its process regardless of it being online or not, it continues to run in the process window. That's why I need it close any current instances, else we just end up with multiples of the same server running.
The server is run from a local computer using direct IP connection, therefore if the local computer isn't connected to the internet, the server wont be reachable to anyone (obviously). The intent for the .bat is to run continuously so even when the user isn't at the computer, it will take care of ensuring the server is online 24/7.
This will be a file I will want to make available to other server hosts who may want to use it to keep themselves online 24/7.
The port check will be to ensure the master server ports are reachable and the fault is/isn't on their side, this is not essential so if it's too much trouble, don't worry.
Inside "Server.bat":
#echo off
echo Server process starting
echo Ctrl+Alt+Del to Kill
Server.exe -batchmode -nographics
All of your assistance and comments are very much welcomed. I tried to generalize this as much as possible to keep it simple, so it can be altered for anyone else who may find use for it with any application.
Sounds like you're working on or with a Windows machine. Power Shell might be an option to write your scripts. I came across this question after investigating Test-Connection and Test-NetConnection, which are both kind of like ping, and the latter lets you test if a port is open. Not sure if there are batch file commands like those, but Power Shell lets you use most batch commands. Both of these commands have tons of examples online, and are very easy to use in your use-case.
You probably want to have a while (true) loop running, and periodically do your ping/port checks. That will satisfy your continual checking requirement. Start-Sleep is a cmdlet to let you pause your script, which you'll want to do in your forever loop.
You can call batch files from Power Shell (another link from another good resource), so that will let you reuse your existing scripts if you don't want to rewrite them in Power Shell.

how to send send a message in remote machine

if I am using the following command command msg * /server:127.0.0.1 Hello world
then it opens pop box and displays Hello world
If I use the similar way to send a message to remote system
msg * /server:192.168.1.56 Hello world then it shows
Error 5 getting session names
whats the reason behind and how to send message to remote machine
remote os can either be windows 7 or windows 8.
Not since Windows XP. It's a security flaw.
msg send messages to terminal sessions on terminal server. Workstations are limited terminal servers, limited to one interactive user, so msg works on local computers.
Anything you can do remotely is always invisible to the user on the remote computer.
You can send a program to display a message using psexec by MS though, its not part of windows. http://technet.microsoft.com/en-us/sysinternals/bb545027.aspx
It may be possible to do it and the method you described should work.
I recently attempted to do this exact operation but I was blocked because if user rights on the PC's and the only way to make this function available was to edit the reg. You will continue to get that error until the Reg on both computers has been edited to allow the messages. Now if you are not on your own computer and you do have system administrators they could have blocked these functions for security purposes. If you want to attempt to edit the registry to allow you to do this you need to follow these instructions
Open the Registry Editor ( regedit.exe ).
In the left panel, locate and then click on the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server
In the right panel, find the key AllowRemoteRPC and be sure the value of the key is 1. If the value is not 1, change it to 1.
Close Registry Editor and restart your computer.
Run MSG.EXE command in the elevated CMD window. Launch it when you hold Ctrl+Shift keys to enter elevated mode.
http://www.cezeo.com/tips-and-tricks/msg-command/
If you run into admin rights errors you will either need to contact the server admins or you will need to find a different way to talk to people in your office :P I recommend gmails messaging system for that. You can log into mail.google.com then click their email address on the bottom left and send them instant messages. As long as they have google up as well or set up email notifications to their phone they can communicate back with you.

C program that connects to remote host and then executes system commands

I've looked around online about executing system commands through a c program, but none of them touched on executing the command after connecting to a remote host such as (this connection prompts for a user password):
sprintf(buffer1,"ssh -l %s %s ",userName,hostName);
system((char*)buffer1);
//Nothing below this executes because the connection has been established
sprintf(buffer2,"shasum sfin.exe > t.sha");
system((char*)buffer2);
Once the connection is closed the program then continues to execute, is there a simple way to keep the execution going?
You'll want to use the function popen instead of system.
http://linux.die.net/man/3/popen
It runs a command, returning a file object that you can write to with functions like fprintf, fwrite, etc., and those commands will go through the ssh process to the remote computer.

Problem with bin/sh -i in a forked process, error: 'can't access tty, job control turned off'

I'm writing a cgi-bin program for my Sheevaplug (running the default Ubuntu install) that displays a shell in a browser page. It is a single C program that is placed in the cgi-bin folder and viewed in a browser. It automatically launches a daemon and the daemon forks an instance of the shell. The cgi-bin communicates with the daemon via shared memory block, and the daemon communicates with the shell by redirecting its stdin/stdout to the shell's stdout/stdin. When you leave the page it automatically turns off the daemon.
It works if I launch it using "/bin/sh" and I send a whole command line at a time from the browser to it. But using that design it's not interactive.
So I changed it to send a character at a time to "/bin/sh" and added "-i" so the shell runs in interactive mode.
When the shell starts up it displays the error "can't access TTY, job control turned off."
It then displays the '$' when it is ready for input and seems to work, but sending delete characters to it just confuses it and it doesn't properly handle deleting. I'm not really sure if it is in interactive mode or not. When I type 'su root' I get the error "must be run from a terminal'.
Any ideas what I am doing wrong?
PS: When I have it done it will be released under the GPL.
For interactive mode, sh wants to be talking to a terminal or something that emulates one (a pseudo-terminal), not just direct IO pipes. Consider using forkpty to start the process you launch the shell from, and talking to the streams provided by that.

Resources