mirror of
https://github.com/netchx/netch.git
synced 2026-05-11 23:45:06 +08:00
简化NTT控制器返回值
This commit is contained in:
@@ -205,15 +205,15 @@ namespace Netch.Controllers
|
|||||||
{
|
{
|
||||||
Global.MainForm.NatTypeStatusText(i18N.Translate("Starting NatTester"));
|
Global.MainForm.NatTypeStatusText(i18N.Translate("Starting NatTester"));
|
||||||
// Thread.Sleep(1000);
|
// Thread.Sleep(1000);
|
||||||
var (nttResult, natType, localEnd, publicEnd) = NTTController.Start();
|
var (result, localEnd, publicEnd) = NTTController.Start();
|
||||||
|
|
||||||
if (nttResult)
|
if (!string.IsNullOrEmpty(publicEnd))
|
||||||
{
|
{
|
||||||
var country = Utils.Utils.GetCityCode(publicEnd);
|
var country = Utils.Utils.GetCityCode(publicEnd);
|
||||||
Global.MainForm.NatTypeStatusText(natType, country);
|
Global.MainForm.NatTypeStatusText(result, country);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Global.MainForm.NatTypeStatusText(natType);
|
Global.MainForm.NatTypeStatusText(result ?? "Error");
|
||||||
|
|
||||||
NttTested = true;
|
NttTested = true;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ namespace Netch.Controllers
|
|||||||
{
|
{
|
||||||
private string _localEnd;
|
private string _localEnd;
|
||||||
private string _publicEnd;
|
private string _publicEnd;
|
||||||
private string _natType;
|
private string _result;
|
||||||
private bool _nttResult;
|
private string _bindingTest;
|
||||||
|
|
||||||
public NTTController()
|
public NTTController()
|
||||||
{
|
{
|
||||||
@@ -22,10 +22,9 @@ namespace Netch.Controllers
|
|||||||
/// 启动 NatTypeTester
|
/// 启动 NatTypeTester
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (bool, string, string, string) Start()
|
public (string, string, string) Start()
|
||||||
{
|
{
|
||||||
_nttResult = false;
|
_result = _localEnd = _publicEnd = null;
|
||||||
_natType = _localEnd = _publicEnd = null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -36,7 +35,9 @@ namespace Netch.Controllers
|
|||||||
Instance.BeginOutputReadLine();
|
Instance.BeginOutputReadLine();
|
||||||
Instance.BeginErrorReadLine();
|
Instance.BeginErrorReadLine();
|
||||||
Instance.WaitForExit();
|
Instance.WaitForExit();
|
||||||
return (_nttResult, _natType, _localEnd, _publicEnd);
|
if (_bindingTest == "Fail")
|
||||||
|
_result = "UdpBlocked";
|
||||||
|
return (_result, _localEnd, _publicEnd);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -50,7 +51,7 @@ namespace Netch.Controllers
|
|||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
return (false, null, null, null);
|
return (null, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,10 +68,12 @@ namespace Netch.Controllers
|
|||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case "Other address is":
|
case "Other address is":
|
||||||
case "Binding test":
|
|
||||||
case "Nat mapping behavior":
|
case "Nat mapping behavior":
|
||||||
case "Nat filtering behavior":
|
case "Nat filtering behavior":
|
||||||
break;
|
break;
|
||||||
|
case "Binding test":
|
||||||
|
_bindingTest = value;
|
||||||
|
break;
|
||||||
case "Local address":
|
case "Local address":
|
||||||
_localEnd = value;
|
_localEnd = value;
|
||||||
break;
|
break;
|
||||||
@@ -78,11 +81,10 @@ namespace Netch.Controllers
|
|||||||
_publicEnd = value;
|
_publicEnd = value;
|
||||||
break;
|
break;
|
||||||
case "result":
|
case "result":
|
||||||
_natType = value;
|
_result = value;
|
||||||
_nttResult = true;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
_natType = str.Last();
|
_result = str.Last();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user