Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.Linq;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace ChangerSSH
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private int porti = 1080;
- private int top = 100;
- Label[] l1 = new Label[50];
- int[,] x = new int[50, 4];
- int sshi = 1;
- internal bool CheckSocksAlive(string host, int port, int TryTimes)
- {
- TryTimes++;
- TcpClient tcpClient = new TcpClient();
- try
- {
- tcpClient.Connect(host, port);
- return true;
- }
- catch (Exception)
- {
- if (TryTimes > 5) return tcpClient.Connected;
- return CheckSocksAlive(host, port, TryTimes);
- //if (tcpClient.Connected) return true;
- //else return false;
- }
- }
- //List<Button> buttons = new List<Button>();
- private void NewBtn_Click(object sender, EventArgs e)
- {
- porti = Int32.Parse(StartPortTbx.Text);
- for (int i = 0; i < Int32.Parse(ThreadsTbx.Text); i++)
- {
- Button newButton = new Button();
- //buttons.Add(newButton);
- newButton.Name = porti.ToString();
- newButton.Height = 23;
- newButton.Width = 90;
- newButton.Left = 300;
- newButton.Top = top;
- newButton.FlatStyle = 0;
- newButton.Text = "Change_" + newButton.Name;
- this.Controls.Add(newButton);
- newButton.Click += new EventHandler(ButtonClickOneEvent);
- l1[i] = new Label();
- l1[i].Name = porti.ToString();
- l1[i].Width = 300;
- l1[i].Left = 10;
- l1[i].Top = top + 5;
- l1[i].Text = newButton.Name;
- this.Controls.Add(l1[i]);
- top = top + 30;
- porti++;
- x[i,0] = i;
- x[i,1] = porti;
- }
- }
- private async void ButtonClickOneEvent(object sender, EventArgs e)
- {
- int iii;
- Button button = sender as Button;
- Label label = sender as Label;
- //MessageBox.Show(button.Name);
- for(iii=0; iii < Int32.Parse(ThreadsTbx.Text); iii++)
- {
- if (l1[iii].Name == button.Name)
- {
- Console.WriteLine("ProcID =" + x[iii, 3]);
- if(x[iii, 3] != 0)
- {
- string PlinkCommand4 = "Taskkill /F /PID " + x[iii, 3] + " /T";
- Process proc4 = new Process();
- proc4.StartInfo.FileName = "CMD.exe";
- proc4.StartInfo.Arguments = "/c " + PlinkCommand4;
- proc4.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
- proc4.Start();
- }
- int port = Int32.Parse(button.Name);
- string[] SshInfo = SshTbx.Lines[sshi - 1].Split('|');
- l1[iii].Text = l1[iii].Name + ": Connecting to " + SshInfo[0];
- l1[iii].Refresh();
- bool conn = false;
- string PlinkCommand = "echo y | plink.exe -ssh -D " + port + " " + SshInfo[1] + "@" + SshInfo[0] + " -N -pw " + SshInfo[2];
- Process proc = new Process();
- proc.StartInfo.FileName = "CMD.exe";
- proc.StartInfo.Arguments = "/c " + PlinkCommand;
- proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
- proc.Start();
- x[iii, 3] = proc.Id;
- await Task.Delay(200);
- conn = CheckSocksAlive("127.0.0.1", port, 2);
- if (conn)
- {
- l1[iii].Text = l1[iii].Name + ": Connected " + SshInfo[0];
- l1[iii].Refresh();
- }
- else
- {
- l1[iii].Text = l1[iii].Name + ": Connect Failed. Click ================>>>>>> ";
- l1[iii].Refresh();
- }
- break;
- };
- }
- sshi++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement