cmit:
plink.exe seems to work fine for me to execute commands on a the router. What problem are you running into? I have a cf webserver app running plink in a cfexecute command allowing it to send comands and receive response via plink. No problems.
cmit:
plink.exe seems to work fine for me to execute commands on a the router. What problem are you running into? I have a cf webserver app running plink in a cfexecute command allowing it to send comands and receive response via plink. No problems.
I am in dire need of your big magic and have NO more to pull out! What am I doing wrong in the following code? Any “hidden” permissions issues I need to be aware of?
Script executed successfully! Eight hours of delicious sleep for YOU! Script failed miserably. No sleep for YOU, slacker!Any assistance would be MOST appreciated!
Steve Edwards
Dad O’Twins
Out of town until next week. When I get back, I will post the script here so that you can see what we are doing. It should be fairly simple since it only took about 20 minutes to throw it together initially. That is why I cannot remember the specifics of how we did it.
dup.
Thanks in advance for your contribution! I’m certain I’m not the only CF developer interested in seeing how you did it.
Webdaddy
Ok. Here you go. This is the abridged version after cmit comments…
This should show all you really need to know.
There are a few variables populated by a database in the beginning.
The CFExecute also has the output redirected to a file so you can see the results of the command for “testing purposes”. If you need to keep this result beyond the millisecond you executed the command, it should not be saved in a flat file that is overwritten each time.
Oh, and it is not required to use the -P switch to set the port if you are using the standard port 22.
Enjoy.
<CFSET filestring = "D:\#get_command.command_filename#">
<CFSET Router_Address = "#get_site_info.Wifi_Site_IP#">
<CFSET Router_Username = "#get_site_info.Repeater_Username#">
<CFSET Router_Password = "#get_site_info.Repeater_Password#">
<CFSET Router_Port = "#get_site_info.Router_Port#">
<CFSET connect_string = "-P #get_site_info.Router_Port# #Router_Username#@#Router_Address# -pw #Router_Password# -T -m #filestring#">
<cfoutput>#connect_string#</cfoutput>
<BR><BR>
<cfexecute name = "d:\downloads\plink"
arguments = " -P #Router_Port# #Router_Username#@#Router_Address# -pw #Router_Password# -T -m #filestring#"
timeout = "100" outputfile="D:\virtualwww\Sites\hypewifi\www\admin\no_app\data_dumps\router_output.txt">
</cfexecute>
<cffile action="READ" file="D:\virtualwww\Sites\hypewifi\www\admin\no_app\data_dumps\router_output.txt" variable="fileoutput">
<pre>
<cfoutput>#fileoutput#</cfoutput>
</pre>
With this ColdFusion snippet you have to take care not to have simultaneous requests to this file, as it’s using a fixed file name for saving and then displaying the commands output.
If you have overlapping requests, this could give interesting results ![]()
And you don’t actually use the Router_Port variable in your plink execution (which is fine, as long as you don’t want to configure the SSH port over your database).
Best regards,
Christian Meis
Whatever… These things are true. Irrelevant to showing someone how a script could be formatted for the use of plink, but true. As I said in an earlier post, this script was built in about 10 minutes (therefore the hard coded 2222 was not removed from testing) and the script does not get used regularly. If it were in an environment that multiple requests were being submitted at once, it would be writing the output to a database record, not a flat file.
[/code]
Hey - no offence intended! ![]()
I just wanted to annotate that in case a ColdFusion newbie would use that script as posted - I have seen this way too often, and just wanted to make this clear…
Best regards,
Christian Meis
You are correct. I should not have posted code that was not cleaned up.
No offense taken. Thanks for noticing the confusing statements. The post has been updated to reflect your comments.
Any development on this issue? How can I shutdown the router through remotely and in an automated process under Win32?
using these:
plink -t -ssh 192.168.1.1 -l <username> -pw <password>
plink -t -pw <password> PuTTYSavedSession
I’m able to connect to the router and the MikroTik command prompt appears but …
Reading the plink manual led me to trying it like this:
plink -t -pw PuTTYSavedSession “/system/shutdown”
plink -t -pw PuTTYSavedSession echo /system/shutdown
plink -t -pw PuTTYSavedSession /system/shutdown
And it’s not working, nothing gets passed through.
Help is appreciated ![]()
P.S. I see now an example for the ssh command in *nix systems posted here:
wiki.mikrotik.com/wiki/Use_SSH_to_execute_commands…
Maybe there’s an alternative to plink that I could use… like the Win32SSH: ssh-1.2.14-win32bin.zip;setupssh381-20040709.zip
THANK YOU!
Hi everyone!!I’m not sure that this is the right place to put this question
And the question is:
Is there any way to get connected on mikrotik router trought ssh2 or ssh using php script??I was looking on php.net site and saw that the php is only suporting ssh2.I know that the mikrotik have ssh access, but I’m not sure that it’ll go with ssh2.
I’m trying to make a web aplication, that could manage mikrotik without using winbox or similar programs…
yes, you can:
$conn = ssh2_connect("192.168.0.1", 22, array('kex' => 'diffie-hellman-group1-sha1')) or die("couldn't connect");
ssh2_auth_password($conn, "admin", "password") or die("coudln't auth");
$shell = ssh2_shell($conn, FALSE);
stream_set_blocking($shell, TRUE);
function conn_exec($cmd) {
global $shell;
echo "<<< $cmd\n";
fwrite($shell, $cmd . "\r");
sleep(1);
fgets($shell);
return trim(fgets($shell));
}
print_r(explode(';', conn_exec(":put [ip firewall filter print as-value]")));
fclose($shell);
Thanks a lot
Know I have a few new ideas ![]()
sry about the english.It’s bad
*now
also you may try to use RouterOS API - it’s easier than parse SSH output =)
I’ll have it on mind
not when you use:
:put [/ interface print as-value]
![]()
haha, almost API ![]()