Filed Under (Code) by Mystalia on 31-05-2008
If you’re looking for an easy way to communicate through ssh without paying rediculous prices for components, then read on.
Behold: SharpSSH (Download). It is a free communications component that is great for ssh.
Add the binary dll’s as a reference to your project.
The usage is surprisingly simple.
Tamir.SharpSsh.SshStream ssh = new Tamir.SharpSsh.SshStream(serverip, username, password);
The server ip does not need a port, it uses standard port 22.
string command = “killall -u username”; // could be any command
ssh.Write(command);
ssh.ReadResponse();
and when you are done…
ssh.Close();
To overcome issues with root password prompting you must set the server so that a username does not require a password.
Filed Under (Code) by Mystalia on 26-05-2008
For some reason, the Visual Studio debugger suppresses this automatically, but the release does not.
It has something to do with DRM signatures, anyway the fix is to open up the entry point in the application (program.cs) and make these changes…
using System;
using System.Collections.Generic;
using System.Windows.Forms;
<span style="color: #ff0000;"> using System.Runtime.InteropServices;</span>
namespace Program
{
[Flags]
public enum ErrorModes : uint
{
SYSTEM_DEFAULT = 0×0,
SEM_FAILCRITICALERRORS = 0×0001,
SEM_NOALIGNMENTFAULTEXCEPT = 0×0004,
SEM_NOGPFAULTERRORBOX = 0×0002,
SEM_NOOPENFILEERRORBOX = 0×8000
}
static class Program
{
// Suppresses “Bad Image” error.
[DllImport("kernel32.dll")]
static extern ErrorModes SetErrorMode(ErrorModes uMode);
[DllImport("kernel32.dll")]
static extern ErrorModes GetErrorMode();
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] Args)
{
SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1(Args));
}
}
}
Filed Under (Code) by Mystalia on 26-05-2008
function PlainResults(<span style="color: #3366ff;">$term</span>)
{
<span style="color: #3366ff;">$content</span> = file_get_contents('<span style="color: #ff0000;">http://www.google.com/search?num=100&safe=off&q=</span>' . <span style="color: #3366ff;">$term</span>);
if (<span style="color: #3366ff;">$content</span> !== false)
{
<span style="color: #3366ff;">$content</span> = str_replace("<span style="color: #ff0000;">http</span>", "<span style="color: #ff0000;">\nhttp</span>", <span style="color: #3366ff;">$content</span>);
<span style="color: #3366ff;">$content</span> = str_replace("<span style="color: #ff0000;">\"</span>", "<span style="color: #ff0000;">\n\"</span>", <span style="color: #3366ff;">$content</span>);
$line = explode(“\n“, $content);
$i = 0;
while($line[$i] != “”)
{
$temp = trim($line[$i]);
if(substr($temp, 0, 21) !== “http://www.google.com” and substr($temp, 0, 1) !== “\”” and substr($temp, strlen($temp) – 1, 1) == “/“)
{
echo “$temp
\n“;
}
$i++;
}
}
This script will output googles directory results as just plain urls.
Filed Under (Code) by Mystalia on 12-05-2008
Apparently this proved a challenge for google, so I converted and simplified some PHP code I found.
This method will turn any byte into a human readable string, handy when dealing with files.
public string ConvertBytes(long Bytes)
{
string[] units = new string[] { "Bytes", "KB", "MB", "GB", "TB", "PB" };
int i;
for (i = 0; Bytes > 1024; i++) { Bytes /= 1024; }
return Bytes.ToString() + " " + units[i];
}