private bool checkVpnClientEasyManager() { m_nConnectionRetryCount = 0; Log("[checkVpnClientEasyManager]"); //SoftEther VPN Client Easy Manager IntPtr hWnd = Interop.FindWindow(null, "SoftEther VPN Client Easy Manager"); if (hWnd == IntPtr.Zero) { Log("Easy Mananger Not found.."); m_procSequence = determineOperationModeNormalOrEasy; timer1.Interval = 100; return(true); } // Log("Now call the server list dialog.."); IntPtr hServerListWnd = Interop.FindWindow(null, "VPN Gate Academic Experimental Project Plugin for SoftEther VPN Client"); if (hServerListWnd == IntPtr.Zero) { Window window = new Window(hWnd); window.PostMessage(Interop.Messages.WM_COMMAND, new IntPtr(0x00459), IntPtr.Zero); timer1.Interval = 200; } m_procSequence = checkVpnServerListWindow; return(true); }
private void button1_Click(object sender, EventArgs e) { try { m_nConnectionRetryMaxLimit = Int32.Parse(textBox1.Text); } catch (FormatException) { Log("Retry count parse error..."); return; } Log("Button Start.."); button1.Enabled = false; button2.Enabled = true; button1.Visible = false; label2.Left = button1.Left; label2.Top = button1.Top; label2.Visible = true; timer2.Enabled = true; label2.Text = "작동 중"; timer2.Interval = 500; // Normal Manager 체크 하는 것 부터 시작. m_nSeqRetryTimeout = 0; m_procSequence = determineOperationModeNormalOrEasy; m_vpnServerList = null; m_nConnectionRetryCount = 0; listView1.Items.Clear(); UpdateUI(); timer1_Tick(null, e); }
public Form1() { InitializeComponent(); m_vpnServerList = null; m_procSequence = checkVpnClientNormalManager; Log("App Run.."); }
private bool checkVpnServerListWindow() { Log("[checkVpnServerListWindow]"); //VPN Gate Academic Experimental Project Plugin for SoftEther VPN Client IntPtr hWnd = Interop.FindWindow(null, "VPN Gate Academic Experimental Project Plugin for SoftEther VPN Client"); if (hWnd == IntPtr.Zero) { Log("No windows found.. wait.."); timer1.Interval = 100; return(true); } //SysListView32 IntPtr wndListView = Interop.FindWindowEx(hWnd, IntPtr.Zero, "SysListView32", null); if (wndListView == IntPtr.Zero) { Log("No ListView for the server list found.. wait.."); timer1.Interval = 100; return(true); } Thread.Sleep(500); if (m_vpnServerList == null) { Log("Current VpnServer List = null"); } else { Log(String.Format("Current VpnServer List items={0}", m_vpnServerList.Count)); } if (m_vpnServerList == null || m_vpnServerList.Count == 0) { UpdateVpnServerList(wndListView); if (m_vpnServerList != null && m_vpnServerList.Count > 0) { timer1.Interval = 10; m_procSequence = checkVpnServerPingTest; Log("Now ping test to the servers.."); return(true); } } else { m_procSequence = connectTryVPNServerItem; return(true); } Log("No more run... stop the sequence.."); return(false); }
private bool checkConnectionProtocolSelection() { //Select VPN Protocol to Connect Log("[checkConnectionProtocolSelection]"); IntPtr hWnd = Interop.FindWindow(null, "Select VPN Protocol to Connect"); if (hWnd == IntPtr.Zero) { Log("No windows found.. wait.."); timer1.Interval = 100; return(true); } //Use &TCP Protocol (Ethernet over HTTPS VPN) (Recommended) List <Window> childWindows = Window.GetAllChildWindows(hWnd); Window protoSelect = null; foreach (var wnd in childWindows) { if (wnd.Caption.CompareTo("Use &TCP Protocol (Ethernet over HTTPS VPN) (Recommended)") == 0) { Log("Radio button[Easy Mode] was found.."); protoSelect = wnd; break; } } if (protoSelect != null) { Log("Now click and select the radio button.."); protoSelect.PostMessage(Interop.Messages.WM_LBUTTONDOWN, new IntPtr(1), new IntPtr(0xC0026)); Thread.Sleep(50); protoSelect.PostMessage(Interop.Messages.WM_LBUTTONUP, new IntPtr(0), new IntPtr(0xC0026)); Thread.Sleep(50); Log("Select OK and close the dialog.."); Window window = new Window(hWnd); window.PostMessage(Interop.Messages.WM_COMMAND, new IntPtr(1), IntPtr.Zero); timer1.Interval = 500; m_procSequence = determineWindowProtocolSelectConnectErrorConnecting; return(true); } return(false); }
private bool checkVpnClientOperatingMode() { Log("[checkVpnClientOperatingMode]"); IntPtr hWnd = Interop.FindWindow(null, "Switch SoftEther VPN Client Operating Mode"); if (hWnd == IntPtr.Zero) { Log("OperatingMode Window Not Found.. Now checking the normal manager.."); m_procSequence = checkVpnClientNormalManager; timer1.Interval = 100; return(true); } List <Window> childWindows = Window.GetAllChildWindows(hWnd); Window easyModeButton = null; foreach (var wnd in childWindows) { if (wnd.Caption.CompareTo("&Easy Mode") == 0) { Log("Radio button[Easy Mode] was found.."); easyModeButton = wnd; break; } } if (easyModeButton != null) { Log("Now click and select the radio button.."); easyModeButton.PostMessage(Interop.Messages.WM_LBUTTONDOWN, new IntPtr(1), new IntPtr(0xC0026)); Thread.Sleep(50); easyModeButton.PostMessage(Interop.Messages.WM_LBUTTONUP, new IntPtr(0), new IntPtr(0xC0026)); Thread.Sleep(50); Log("Select OK and close the dialog.."); Window window = new Window(hWnd); window.PostMessage(Interop.Messages.WM_COMMAND, new IntPtr(1), IntPtr.Zero); timer1.Interval = 500; m_procSequence = checkVpnClientEasyManager; return(true); } return(false); }
private bool connectTryVPNServerItem() { Log("[connectTryVPNServerItem]"); IntPtr hWnd = Interop.FindWindow(null, "VPN Gate Academic Experimental Project Plugin for SoftEther VPN Client"); if (hWnd == IntPtr.Zero) { Log("No windows found.. wait.."); timer1.Interval = 100; return(true); } //SysListView32 IntPtr wndListView = Interop.FindWindowEx(hWnd, IntPtr.Zero, "SysListView32", null); if (wndListView == IntPtr.Zero) { Log("No ListView for the server list found.. wait.."); timer1.Interval = 100; return(true); } ListView listView = new ListView(wndListView); listView.SelectItem(m_vpnServerList[0].nItemIndex); Thread.Sleep(100); m_nConnectionRetryCount = 0; ListViewItem lvItem = listView1.FindItemWithText(m_vpnServerList[0].raw_ip); if (lvItem != null) { lvItem.SubItems[4].Text = "Connecting.."; lvItem.Focused = true; listView1.TopItem = lvItem; } Window dlg = new Window(hWnd); dlg.PostMessage(Interop.Messages.WM_COMMAND, new IntPtr(1), IntPtr.Zero); m_procSequence = determineWindowProtocolSelectConnectErrorConnecting; m_nSeqRetryTimeout = 0; timer1.Interval = 200; return(true); }
private bool determineWindowProtocolSelectConnectErrorConnecting() { IntPtr hWndProtocol = Interop.FindWindow(null, "Select VPN Protocol to Connect"); IntPtr hWndConnectError = Interop.FindWindow(null, "Connect Error - VPN Gate Connection"); IntPtr hWndConnecting = Interop.FindWindow(null, "Connecting to \"VPN Gate Connection\"..."); Log("[determineWindowProtocolSelectConnectErrorConnecting]"); timer1.Interval = 20; if (hWndProtocol != IntPtr.Zero && hWndConnectError == IntPtr.Zero && hWndConnecting == IntPtr.Zero) { m_procSequence = checkConnectionProtocolSelection; } else if (hWndProtocol == IntPtr.Zero && hWndConnectError != IntPtr.Zero && hWndConnecting == IntPtr.Zero) { m_procSequence = waitForConnectionEstablishOrRetry; } else if (hWndProtocol == IntPtr.Zero && hWndConnectError == IntPtr.Zero && hWndConnecting != IntPtr.Zero) { if (m_vpnServerList.Count > 0) { Log(String.Format("Now connecting.. {0}", m_vpnServerList[0].qual_ip)); } else { Log("Now connecting.. UnknownIP"); } timer1.Interval = 1000; m_procSequence = waitForConnectionEstablishOrRetry; } else if (m_nSeqRetryTimeout > 3) { timer1.Interval = 500; m_nSeqRetryTimeout = m_nSeqRetryTimeout + 1; } else { m_nSeqRetryTimeout = 0; m_procSequence = checkVpnClientEasyManager; } return(true); }
private bool determineOperationModeNormalOrEasy() { Window wndNormalMode = null; Window wndEasyMode = null; IntPtr hWnd = Interop.FindWindow(null, "SoftEther VPN Client Manager"); if (hWnd != IntPtr.Zero) { Log("Normal Mode Window Found..."); wndNormalMode = new Window(hWnd); } timer1.Interval = 10; hWnd = Interop.FindWindow(null, "SoftEther VPN Client Easy Manager"); if (hWnd != IntPtr.Zero) { Log("Easy Mode Window Found..."); wndEasyMode = new Window(hWnd); } if (wndEasyMode != null && wndEasyMode.Visible) { Log("Easy mode is visible ..."); m_procSequence = checkVpnClientEasyManager; } else if (wndNormalMode != null && wndNormalMode.Visible) { Log("Normal mode is visible ..."); m_procSequence = checkVpnClientNormalManager; } else { Log("Waiting for the SoftEtherVPN ..."); timer1.Interval = 500; } return(true); }
private bool runEtherVPNProcess__() { Log("[runEtherVPNProcess]"); String process_name = "vpncmgr_x64.exe"; Process[] pname = Process.GetProcessesByName(process_name); if (pname.Length == 0) { Log("vpncmgr_x64.exe Process not found... Now run it..."); try { ProcessStartInfo psi = new ProcessStartInfo(); psi.Verb = "open"; psi.FileName = @"C:\\Program Files\\SoftEther VPN Client\\" + process_name; psi.UseShellExecute = true; Process.Start(psi); timer1.Interval = 500; } catch (Exception) { Log("Ether VPN 프로세스 실행 실패.."); MessageBox.Show("Ether VPN 프로세스 실행 실패!", Text); //e.Message; button2_Click(null, null); return(false); } } else { Log("SoftEtherVPN process is running already.."); timer1.Interval = 100; } m_procSequence = determineOperationModeNormalOrEasy; return(true); }
private bool waitForConnectionEstablishOrRetry() { Log("[waitForConnectionEstablishOrRetry]"); //Connect Error - VPN Gate Connection IntPtr hWnd = Interop.FindWindow(null, "Connect Error - VPN Gate Connection"); if (hWnd == IntPtr.Zero) { timer1.Interval = 500; hWnd = Interop.FindWindow(null, "SoftEther VPN Client Easy Manager"); if (hWnd != IntPtr.Zero) { IntPtr hWnd2 = Interop.FindWindowEx(hWnd, IntPtr.Zero, "SysListView32", null); if (hWnd2 != IntPtr.Zero) { ListView listView = new ListView(hWnd2); if (listView.ItemCount == 0) { timer1.Interval = 10; m_procSequence = checkVpnClientEasyManager; } } else { Log("No windows found.. wait.."); } } else { Log("No windows found.. wait.."); } return(true); } Window window = new Window(hWnd); Log(String.Format("Cur Retry={0} Max Retry={1}", m_nConnectionRetryCount, m_nConnectionRetryMaxLimit)); // 최대 시도 회수를 넘으면 연결 취소한다. if (m_nConnectionRetryCount >= m_nConnectionRetryMaxLimit) { Log("Now cancel retrying.."); ListViewItem lvItem = listView1.FindItemWithText(m_vpnServerList[0].raw_ip); if (lvItem != null) { lvItem.SubItems[4].Text = "Reconn Fail"; } if (m_vpnServerList.Count > 0) { m_vpnServerList.RemoveAt(0); } window.PostMessage(Interop.Messages.WM_COMMAND, new IntPtr((int)DialogResult.Cancel), IntPtr.Zero); m_procSequence = checkVpnClientEasyManager; } // 최대 시도 회수를 넘지 않았으면 재시도 한다. else { Log("Now retrying.."); ListViewItem lvItem = listView1.FindItemWithText(m_vpnServerList[0].raw_ip); if (lvItem != null) { lvItem.SubItems[4].Text = String.Format("Reconn [{0}]", m_nConnectionRetryCount); } m_nConnectionRetryCount = m_nConnectionRetryCount + 1; window.PostMessage(Interop.Messages.WM_COMMAND, new IntPtr((int)DialogResult.OK), IntPtr.Zero); } timer1.Interval = 200; return(true); }
private bool checkVpnServerPingTest() { Log("[checkVpnServerPingTest]"); int threadCount = 0; foreach (var item in m_vpnServerList) { if (item.pingTest != null && !item.pingTest.JobFinish) { threadCount++; } } Log(String.Format("Check Current PingTest = {0}", threadCount)); if (threadCount >= 10) { timer1.Interval = 300; return(true); } for (int i = 0; i < m_vpnServerList.Count; i++) { VPNSERVERITEM item = m_vpnServerList[i]; if (item.pingTest == null) { item.pingTest = new PingTest(item.qual_ip); item.pingTest.UserData = item; item.pingTest.PingThreadStartEvent += PingTestThreadStart; item.pingTest.PingThreadErrorEvent += PingTestThreadError; item.pingTest.PingThreadFinshEvent += PingTestThreadFinish; item.pingTest.Start(true); threadCount++; m_vpnServerList[i] = item; if (threadCount >= 10) { break; } } } Log(String.Format("Adjusted Current PingTest = {0}", threadCount)); if (threadCount > 0) { timer1.Interval = 300; return(true); } List <String> itemsToRemove = new List <string>(); // 이제 PING Test가 완료 됨. for (int i = m_vpnServerList.Count - 1; i >= 0; i--) { VPNSERVERITEM item = m_vpnServerList[i]; if (item.pingTest == null) { itemsToRemove.Add(item.raw_ip); m_vpnServerList.RemoveAt(i); continue; } if (item.pingTest.JobFinish && !item.pingTest.ResultOK) { itemsToRemove.Add(item.raw_ip); m_vpnServerList.RemoveAt(i); } } // 이제 List View에서도 삭제 한다. foreach (String item in itemsToRemove) { ListViewItem lvItem = listView1.FindItemWithText(item); if (lvItem != null) { listView1.Items.Remove(lvItem); } } for (int i = listView1.Items.Count - 1; i >= 0; i--) { ListViewItem item = listView1.Items[i]; if (item.SubItems[3].Text.Length == 0 && item.SubItems[4].Text.Length == 0) { listView1.Items.RemoveAt(i); } } Log(String.Format("Ultimate VPN Server Count = {0}", m_vpnServerList.Count)); // m_vpnServerList.OrderByDescending(p => p.pingTest.PingSpeed); m_vpnServerList.Sort( delegate(VPNSERVERITEM p1, VPNSERVERITEM p2) { int compareDate = 1; if (p1.pingTest.PingSpeed < p2.pingTest.PingSpeed) { compareDate = -1; } return(compareDate); } ); timer1.Interval = 10; m_procSequence = connectTryVPNServerItem; return(true); }
private bool checkVpnClientNormalManager() { Log("[checkVpnClientNormalManager]"); // IntPtr hWnd = Interop.FindWindow(null, "SoftEther VPN Client Manager"); if (hWnd == IntPtr.Zero) { Log("Not found.. move to check Easy Manager.."); m_procSequence = checkVpnClientEasyManager; timer1.Interval = 100; return(true); } Window window = new Window(hWnd); Log("Normal Manager found.. Check it visible."); if (!window.Visible) { Log("Normal Manager is invisible.. check it EasyManager."); m_procSequence = checkVpnClientEasyManager; timer1.Interval = 10; return(true); } Log("Call the operation mode dialog to change to the easy manager."); // Normal Mode이면 Simple Mode로 Mode를 바꾼다. window.PostMessage(Interop.Messages.WM_COMMAND, new IntPtr(0x9c9E), IntPtr.Zero); timer1.Interval = 500; m_procSequence = checkVpnClientOperatingMode; return(true); /* * * * List<Window> childWindows = Window.GetAllChildWindows(hWnd); * ListView listView = null; * foreach ( var wnd in childWindows) * { * if( wnd.ClassName == "SysListView32") * { * if( wnd.ControlID == 0x0417 ) * { * listView = new ListView(wnd.Handle); * break; * } * } * } * * if (listView == null) * { * timer1.Interval = 200; * return true; * } * * timer1.Interval = 200; * int count = listView.ItemCount; * * // item이 2개면 IDLE 상태. * if( count == 2 ) * { * listView.SelectItem(1); * listView.PostMessage(Interop.Messages.WM_LBUTTONDOWN, new IntPtr(1), new IntPtr(0x4000C5)); * Thread.Sleep(50); * listView.PostMessage(Interop.Messages.WM_LBUTTONUP, new IntPtr(0), new IntPtr(0x4000C5)); * Thread.Sleep(50); * listView.PostMessage(Interop.Messages.WM_LBUTTONDBLCLK, new IntPtr(1), new IntPtr(0x4000C5)); * return true; * } * //item이 3개면 접속 시도 상태. * else if( count == 3 ) * { * * }*/ }