/// <summary> /// 测试节点延迟 /// </summary> private void TestLine() { Task.Run(new Action(() => { string hostname = EncryptsHelper.Decrypt(shadowsocksR.HostName); int result = int.Parse(NetWorkHelper.GetIPPing(hostname)); if (result > 0 && result < 100) { lbPingText.ForeColor = Color.LimeGreen; } else if (result > 90 && result < 200) { lbPingText.ForeColor = Color.Yellow; } else if (result == 0 || result >= 200) { lbPingText.ForeColor = Color.Red; } if (lbPingText.InvokeRequired) { lbPingText.BeginInvoke(new Action(() => { lbPingText.Text = result.ToString() + " ms"; })); } })); }
public override void BeforeHandle <TRequest>(InspectContext <TRequest> inspectCxt) { inspectCxt.Trace.Start(); inspectCxt.Trace.LocalIp = NetWorkHelper.GetLocalIp(); inspectCxt.Trace.Parameters = JsonHelper.ToJson(inspectCxt.Request); }
private void GetIpAndConnect(object sender, EventArgs e) { try { var ipAddress = editIpText.Text; var editor = preferences.Edit(); editor.PutString("ipAddress", ipAddress); editor.Commit(); NetWorkHelper.Connect(ipAddress); } catch (Exception ex) { UIHelper.ShowMessage("Connection error:" + ex.Message, this); return; } if (NetWorkHelper.IsConnected) { connectButton.Click -= GetIpAndConnect; connectButton.Text = "Stop"; connectButton.Click += CloseConnection; MainActivity.Tabs.SetCurrentTabByTag("wheel"); } }
public bool OnUpdateAccelerometer(Accelerometer.Accelerometer accelerometer) { try { NetWorkHelper.Send(string.Format("^{0}|{1}|{2}|{3}|{4}|{5}|{6}$", accelerometer.Rotation, progressBrake, progressRun, _button01Clicked, _button02Clicked, _button03Clicked, _button04Clicked)); _button01Clicked = 0; _button02Clicked = 0; _button03Clicked = 0; _button04Clicked = 0; } catch (SocketException ex) { //UIHelper.ShowMessage("Sending error:" + ex.Message, this); NetWorkHelper.Reconnect(); } catch (Java.Net.SocketException ex) { //UIHelper.ShowMessage("Sending error:" + ex.Message, this); NetWorkHelper.Reconnect(); } catch (Exception ex) { UIHelper.ShowMessage("Sending error:" + ex.Message, this); } return(NetWorkHelper.IsConnected); }
public void PortInUseTest() { HttpListener _httpListner = new HttpListener(); _httpListner.Prefixes.Add("http://*:8080/"); _httpListner.Start(); Assert.IsTrue(NetWorkHelper.PortInUse(8080)); _httpListner.Close(); }
public void OnAwake() { NetWorkHelper.m_instance = this; this.InitClient(); for (int i = 0; i < this.listServer.Count; i++) { this.listServer[i].OnAwake(); } this._gateReconnection.OnAwake(); }
/// <summary> /// 测试延迟 /// </summary> private void TestIP() { Task.Run(new Action(() => { foreach (SkinListBoxItem item in skinListBox1.Items) { string hostname = item.Tag.ToString(); string remark = ssList[hostname]; string result = NetWorkHelper.GetIPPing(hostname); item.Text = remark + " " + result + " ms"; } })); }
protected override void OnCreate(Bundle savedInstanceState) { preferences = GetPreferences(FileCreationMode.Private); netWorkHelper = new NetWorkHelper(); base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.SetupLayout); editIpText = FindViewById <EditText>(Resource.Id.editIpText); connectButton = FindViewById <Button>(Resource.Id.connectButton); connectButton.Click += GetIpAndConnect; var ipAddress = preferences.GetString("ipAddress", string.Empty); editIpText.Text = ipAddress; }
private void AddGameIcon(object sender) { string path = System.Environment.CurrentDirectory; string url = EncryptsHelper.Decrypt(ConfigurationManager.ConnectionStrings["GamesURL"].ToString()); foreach (IconList list in panel.Controls) { string iconpath = string.Format(path + @"\res\{0}.png", list.gameCode); if (!File.Exists(iconpath)) { NetWorkHelper.ImgSave(url + list.gameCode + ".png", iconpath); } list.Image = Image.FromFile(iconpath); } }
public override void BeforeHandle <TRequest>(InspectContext <TRequest> inspectCxt) { if (inspectCxt.RequestContext == null) { inspectCxt.RequestContext = new RequestContext(); inspectCxt.Trace.RequestContext = inspectCxt.RequestContext; } if (inspectCxt.RequestContext.Device == null) { inspectCxt.RequestContext.Device = new RequestDevice(); } if (inspectCxt.RequestContext.Channel == null) { inspectCxt.RequestContext.Channel = new RequestChannel(); } inspectCxt.RequestContext.Device.Ip = NetWorkHelper.GetClientIP(); inspectCxt.RequestContext.Channel.UserAgent = HttpContext.Current.Request.UserAgent; do { if (string.IsNullOrEmpty(inspectCxt.RequestContext.Device.DeviceType)) { inspectCxt.RequestContext.Device.DeviceType = "Andriod"; if (!string.IsNullOrEmpty(inspectCxt.RequestContext.Channel.UserAgent) && inspectCxt.RequestContext.Channel.UserAgent.IndexOf("iPhone", StringComparison.OrdinalIgnoreCase) >= 0) { inspectCxt.RequestContext.Device.DeviceType = "IPhone"; } break; } if (inspectCxt.RequestContext.Device.DeviceType.IndexOf("ios", StringComparison.OrdinalIgnoreCase) >= 0) { inspectCxt.RequestContext.Device.DeviceType = "IPhone"; break; } } while (false); }
public override StartCommandResult OnStartCommand(Android.Content.Intent intent, StartCommandFlags flags, int startId) { netWorkHelper = new NetWorkHelper(); var ip = intent.GetStringExtra("ip"); try { NetWorkHelper.Connect(ip); } catch (Exception ex) { Log.Debug("NetworkService", "Connection error:" + ex.Message); } if (NetWorkHelper.IsConnected) { NetWorkHelper.Send("I connected with you!"); } // Return the correct StartCommandResult for the type of service you are building return(StartCommandResult.NotSticky); }
private void OnPeerDisconnected(MobaMessage msg) { PeerDisconnectedMessage peerDisconnectedMessage = msg.Param as PeerDisconnectedMessage; if (peerDisconnectedMessage == null) { return; } NetWorkHelper.ServerType serverType = NetWorkHelper.ServerType.none; switch (peerDisconnectedMessage.PeerType) { case MobaPeerType.C2Master: serverType = NetWorkHelper.ServerType.master; NetWorkHelper.DebugInfo("MasterServer:networkHelper 检测到断线"); break; case MobaPeerType.C2Lobby: serverType = NetWorkHelper.ServerType.lobby; break; case MobaPeerType.C2PvpServer: serverType = NetWorkHelper.ServerType.pvp; break; case MobaPeerType.C2GateServer: serverType = NetWorkHelper.ServerType.Gate; break; } if (this.dicServer.ContainsKey(serverType)) { this.dicServer[serverType].OnDisconnected(peerDisconnectedMessage.DisconnectedType); } if (serverType != NetWorkHelper.ServerType.pvp) { MobaMessageManager.ExecuteMsg(MobaMessageManager.GetMessage((ClientMsg)20002, peerDisconnectedMessage, 0f)); } }
public bool OnUpdateAccelerometer(Accelerometer.Accelerometer accelerometer) { try { NetWorkHelper.Send(string.Format("^{0}|{1}|{2}|{3}$", accelerometer.Rotation, progressBrake, progressRun, GetButtonStatecPacked())); ClearButtonStates(); } catch (SocketException ex) { UIHelper.ShowMessage("Sending error:" + ex.Message, this); //NetWorkHelper.Reconnect(); } catch (Java.Net.SocketException ex) { UIHelper.ShowMessage("Sending error:" + ex.Message, this); //NetWorkHelper.Reconnect(); } catch (Exception ex) { UIHelper.ShowMessage("Sending error:" + ex.Message, this); } return(NetWorkHelper.IsConnected); }
public SamReader(NetworkStream samStream) { _netHelper = new NetWorkHelper(samStream); _stateHelper.SetInitializedState(); RunThreadImpl(); }
public bool Start() { string TUNTAPaddress = "10.0.0.2"; string TUNTAPgw = "10.0.0.1"; string hostName = "127.0.0.1"; string port = "2801"; // 查找并安装 TAP 适配器 if (string.IsNullOrEmpty(TUNTAP.GetComponentID())) { //CCWin.MessageBoxEx.Show("未检测到虚拟网卡驱动,驱动即将自动安装,请在弹出的窗口内点击'始终安装此驱动程序软件',并重新加速!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Information); TUNTAP.addtap(); } string path = System.Environment.CurrentDirectory; if (!Directory.Exists(path + @"\bin"))//如果不存在就创建bin文件夹 { Directory.CreateDirectory(path + @"\bin"); } if (!File.Exists(path + @"\bin\Accelerator.exe"))//tun2socks.exe不存在就从资源导出 { CCWin.MessageBoxEx.Show("驱动文件丢失,请重新安装本软件!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } string url = EncryptsHelper.Decrypt(ConfigurationManager.ConnectionStrings["GamesURL"].ToString()); string tempParh = Path.GetTempPath(); string routepath = tempParh + "routetmp.txt"; if (File.Exists(tempParh + "routetmp.txt")) { File.Delete(tempParh + "routetmp.txt"); } NetWorkHelper.RoutetxtSave(url + MainFrm.CurrentGame.SerialCode + ".txt", routepath); if (!File.Exists(tempParh + "routetmp.txt")) { CCWin.MessageBoxEx.Show("获取路由表文件失败,请联系开发者!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } Task.Run(() => { //修改路由表文件 string routeif = TUNTAPController.GetIF().ToString(); //防止文本字符中有特殊字符。必须用Encoding.Default StreamReader reader = new StreamReader(tempParh + "routetmp.txt", Encoding.Default); String a = reader.ReadToEnd(); a = a.Replace("IFZ", $"{routeif}");//替换IF值 StreamWriter readTxt = new StreamWriter(tempParh + "routetmp1.txt", false, Encoding.Default); readTxt.Write(a); readTxt.Flush(); readTxt.Close(); reader.Close(); File.Copy(tempParh + "routetmp1.txt", tempParh + "routetmp.txt", true); File.Delete(tempParh + "routetmp1.txt"); }); var argument = new StringBuilder(); //argument.Append( // $"-tunAddr {TUNTAPaddress} -tunGw {TUNTAPgw} -dnsServer 8.8.8.8,8.8.4.4 -proxyType shadowsocks -proxyServer {hostName}:{port} " + // $"-proxyCipher {method} -proxyPassword {pwd}"); argument.Append( $"-tunAddr {TUNTAPaddress} -tunGw {TUNTAPgw} -dnsServer 8.8.8.8,8.8.4.4 -proxyServer {hostName}:{port} "); NoBoundaries = new Process(); NoBoundaries.StartInfo.FileName = path + @"\bin\Accelerator.exe"; NoBoundaries.StartInfo.Arguments = argument.ToString(); NoBoundaries.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动 NoBoundaries.StartInfo.RedirectStandardInput = true; //接受来自调用程序的输入信息 NoBoundaries.StartInfo.RedirectStandardOutput = true; //由调用程序获取输出信息 NoBoundaries.StartInfo.CreateNoWindow = true; //不显示程序窗口 NoBoundaries.Start(); return(true); }
public void GetHostNameTest() { Assert.AreEqual("YanZhiwei-PC", NetWorkHelper.GetHostName()); }