mirror of
https://github.com/proxysu/ProxySU.git
synced 2025-02-16 14:43:14 +03:00
优化纯ipv6安装,自动查找最快Nat64网关
This commit is contained in:
parent
0734887044
commit
066103adf4
@ -31,6 +31,29 @@ using Microsoft.Win32;
|
||||
|
||||
namespace ProxySU
|
||||
{
|
||||
class NatDns64
|
||||
{
|
||||
private string ipaddr { set; get; } //Dns64网关地址
|
||||
private int avg { set; get; } //ping的平均值
|
||||
|
||||
public NatDns64(string IpAddr, int Avg)
|
||||
{
|
||||
this.ipaddr = IpAddr;
|
||||
this.avg = Avg;
|
||||
}
|
||||
|
||||
public string IpAddr
|
||||
{
|
||||
get { return ipaddr; }
|
||||
set { this.ipaddr = IpAddr; }
|
||||
}
|
||||
|
||||
public int Avg
|
||||
{
|
||||
get { return avg; }
|
||||
set { this.avg = Avg; }
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// MainWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
@ -6761,6 +6784,38 @@ namespace ProxySU
|
||||
}
|
||||
#endregion
|
||||
|
||||
//安装日志另存为...
|
||||
private void ButtonSaveInstalledLog_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string logSaveName = ChooseSaveFile("Log Save as...", $"{pwdir}");
|
||||
if (String.IsNullOrEmpty(logSaveName) == false)
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter($"{logSaveName}"))
|
||||
{
|
||||
sw.WriteLine($"{TextBoxMonitorCommandResults.Text}");
|
||||
}
|
||||
}
|
||||
}
|
||||
private string ChooseSaveFile(string title, string initFolder)
|
||||
{
|
||||
SaveFileDialog dlg = new SaveFileDialog();
|
||||
dlg.Title = title;
|
||||
string localTime = DateTime.Now.ToLocalTime().ToString().Replace(' ', '-').Replace(':', '-').Replace('/', '-').Replace('\\', '-');
|
||||
dlg.FileName = $"{TextBoxHost.Text.Replace(':', '_')}_{localTime}.txt"; // Default file name
|
||||
dlg.DefaultExt = ".txt"; // Default file extension
|
||||
dlg.Filter = "Text documents|*.txt"; // Filter files by extension
|
||||
dlg.InitialDirectory = initFolder;
|
||||
|
||||
// Process save file dialog box results
|
||||
if (dlg.ShowDialog() == true)
|
||||
{
|
||||
return dlg.FileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -6865,25 +6920,27 @@ namespace ProxySU
|
||||
MainWindowsShowInfo(currentStatus);
|
||||
|
||||
}
|
||||
SetUpNat64(client, true);
|
||||
//FilterFastestIP(client);
|
||||
//string cmdErr = client.RunCommand(@"aaa ee").Error;
|
||||
//MessageBox.Show(cmdErr);
|
||||
SshCommand cmdResult = client.RunCommand(@"pwd");
|
||||
string result = cmdResult.Result;
|
||||
MessageBox.Show("result:" + result);
|
||||
string error = cmdResult.Error;
|
||||
MessageBox.Show("err:" + error);
|
||||
//SshCommand cmdResult = client.RunCommand(@"pwd");
|
||||
//string result = cmdResult.Result;
|
||||
//MessageBox.Show("result:" + result);
|
||||
//string error = cmdResult.Error;
|
||||
//MessageBox.Show("err:" + error);
|
||||
|
||||
int cmdExitStatus = cmdResult.ExitStatus;
|
||||
MessageBox.Show("cmdExitStatus:" + cmdExitStatus.ToString());
|
||||
//int cmdExitStatus = cmdResult.ExitStatus;
|
||||
//MessageBox.Show("cmdExitStatus:" + cmdExitStatus.ToString());
|
||||
|
||||
SshCommand cmdResultCat = client.RunCommand(@"cat tt.t");
|
||||
string resultCat = cmdResultCat.Result;
|
||||
MessageBox.Show("resultCat:" + resultCat);
|
||||
string errorCat = cmdResultCat.Error;
|
||||
MessageBox.Show("errCat:" + errorCat);
|
||||
//SshCommand cmdResultCat = client.RunCommand(@"cat tt.t");
|
||||
//string resultCat = cmdResultCat.Result;
|
||||
//MessageBox.Show("resultCat:" + resultCat);
|
||||
//string errorCat = cmdResultCat.Error;
|
||||
//MessageBox.Show("errCat:" + errorCat);
|
||||
|
||||
cmdExitStatus = cmdResultCat.ExitStatus;
|
||||
MessageBox.Show("cmdExitStatus:" + cmdExitStatus.ToString());
|
||||
//cmdExitStatus = cmdResultCat.ExitStatus;
|
||||
//MessageBox.Show("cmdExitStatus:" + cmdExitStatus.ToString());
|
||||
|
||||
//SoftInstalledSuccessOrFail(client, "v2ray", @"/usr/local/bin/v2ray");
|
||||
//CaddyInstall(client);
|
||||
@ -6966,14 +7023,29 @@ namespace ProxySU
|
||||
{
|
||||
if(set == true)
|
||||
{
|
||||
//****** "正在查找最快的Nat64网关......" ******
|
||||
currentStatus = Application.Current.FindResource("DisplayInstallInfo_FindFastestSetUpNat64").ToString();
|
||||
MainWindowsShowInfo(currentStatus);
|
||||
string[] dns64 = new string[2];
|
||||
dns64 = FilterFastestIP(client);
|
||||
|
||||
//****** "当前主机最快的Nat64网关为:" ******
|
||||
currentStatus = Application.Current.FindResource("DisplayInstallInfo_FindFastestNat64AsIs").ToString();
|
||||
MainWindowsShowInfo(currentStatus);
|
||||
|
||||
currentStatus = dns64[0];
|
||||
MainWindowsShowInfo(currentStatus);
|
||||
currentStatus = dns64[1];
|
||||
MainWindowsShowInfo(currentStatus);
|
||||
|
||||
//****** "正在设置Nat64网关......" ******
|
||||
currentStatus = Application.Current.FindResource("DisplayInstallInfo_SetUpNat64").ToString();
|
||||
MainWindowsShowInfo(currentStatus);
|
||||
sshShellCommand = @"mv /etc/resolv.conf /etc/resolv.conf.bak";
|
||||
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
|
||||
sshShellCommand = @"echo ""nameserver 2a09:11c0:f1:bbf0::70"" >>/etc/resolv.conf";
|
||||
sshShellCommand = $"echo \"nameserver {dns64[0]}\" >>/etc/resolv.conf";
|
||||
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
|
||||
sshShellCommand = @"echo ""nameserver 2a03:7900:2:0:31:3:104:161"" >>/etc/resolv.conf";
|
||||
sshShellCommand = $"echo \"nameserver {dns64[1]}\" >>/etc/resolv.conf";
|
||||
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
|
||||
}
|
||||
else
|
||||
@ -6989,7 +7061,50 @@ namespace ProxySU
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//筛选最优的NAT64地址
|
||||
private string[] FilterFastestIP(SshClient client)
|
||||
{
|
||||
string[] gateNat64 = {
|
||||
"2a01:4f9:c010:3f02::1",
|
||||
"2001:67c:2b0::4",
|
||||
"2001:67c:2b0::6",
|
||||
"2a09:11c0:f1:bbf0::70",
|
||||
"2a01:4f8:c2c:123f::1",
|
||||
"2001:67c:27e4:15::6411",
|
||||
"2001:67c:27e4::64",
|
||||
"2001:67c:27e4:15::64",
|
||||
"2001:67c:27e4::60",
|
||||
"2a00:1098:2b::1",
|
||||
"2a03:7900:2:0:31:3:104:161",
|
||||
"2a00:1098:2c::1",
|
||||
"2a09:11c0:100::53",
|
||||
};
|
||||
string[] returnstr = new string[2];
|
||||
List<NatDns64> NatDns64s = new List<NatDns64>();
|
||||
foreach (string gateip in gateNat64)
|
||||
{
|
||||
sshShellCommand = $"ping -c4 {gateip} | grep avg | awk '{{print $4}}'|cut -d/ -f2";
|
||||
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
|
||||
if (String.IsNullOrEmpty(currentShellCommandResult) != true)
|
||||
{
|
||||
if (float.TryParse(currentShellCommandResult, out float delay) == true)
|
||||
{
|
||||
|
||||
int delayInt = (int)(delay * 1000);
|
||||
NatDns64 ipaddr = new NatDns64($"{gateip}", delayInt);
|
||||
NatDns64s.Add(ipaddr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
NatDns64s = NatDns64s.OrderBy(o => o.Avg).ToList();
|
||||
returnstr[0] = NatDns64s[0].IpAddr;
|
||||
returnstr[1] = NatDns64s[1].IpAddr;
|
||||
|
||||
return returnstr;
|
||||
}
|
||||
|
||||
//纯ipv6主机安装脚本处理
|
||||
//private void Ipv6ScriptEdit(SshClient client,string scriptFile)
|
||||
//{
|
||||
@ -8078,38 +8193,7 @@ namespace ProxySU
|
||||
|
||||
#endregion
|
||||
|
||||
//安装日志另存为...
|
||||
private void ButtonSaveInstalledLog_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string logSaveName = ChooseSaveFile("Log Save as...", $"{pwdir}");
|
||||
if (String.IsNullOrEmpty(logSaveName) == false)
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter($"{logSaveName}"))
|
||||
{
|
||||
sw.WriteLine($"{TextBoxMonitorCommandResults.Text}");
|
||||
}
|
||||
}
|
||||
}
|
||||
private string ChooseSaveFile(string title, string initFolder)
|
||||
{
|
||||
SaveFileDialog dlg = new SaveFileDialog();
|
||||
dlg.Title = title;
|
||||
string localTime = DateTime.Now.ToLocalTime().ToString().Replace(' ','-').Replace(':','-').Replace('/','-').Replace('\\','-');
|
||||
dlg.FileName = $"{TextBoxHost.Text.Replace(':','_')}_{localTime}.txt"; // Default file name
|
||||
dlg.DefaultExt = ".txt"; // Default file extension
|
||||
dlg.Filter = "Text documents|*.txt"; // Filter files by extension
|
||||
dlg.InitialDirectory = initFolder;
|
||||
|
||||
// Process save file dialog box results
|
||||
if (dlg.ShowDialog() == true)
|
||||
{
|
||||
return dlg.FileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -574,25 +574,29 @@ namespace ProxySU
|
||||
configDomainSavePath = CreateConfigSaveDir(proxyfolder, MainWindow.ReceiveConfigurationParameters[4]);
|
||||
string configSavePath = configDomainSavePath;
|
||||
|
||||
//string mtprotoJsonPath = @"mtproto_config\mtproto_info.json";
|
||||
//using (StreamReader readerJson = File.OpenText(mtprotoJsonPath))
|
||||
//{
|
||||
//JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson));
|
||||
|
||||
RadioButtonMtgIpv4.IsChecked = true;
|
||||
JObject jObjectJson = JObject.Parse(MainWindow.ReceiveConfigurationParameters[9]);
|
||||
|
||||
TextBoxURLMtgTgIpv4.Text = jObjectJson["ipv4"]["tg_url"].ToString();
|
||||
ImageShareQRcodeMtgTgIpv4.Source = CreateQRCode(TextBoxURLMtgTgIpv4.Text, $"{configSavePath}\\QRIpv4Tg.bmp");
|
||||
using (StreamWriter sw = new StreamWriter($"{configSavePath}\\urlIpv4Tg.txt"))
|
||||
if (jObjectJson["ipv4"]["tg_url"].ToString().Contains("nil") == false)
|
||||
{
|
||||
sw.WriteLine(TextBoxURLMtgTgIpv4.Text);
|
||||
RadioButtonMtgIpv4.Visibility = Visibility.Visible;
|
||||
TextBoxURLMtgTgIpv4.Text = jObjectJson["ipv4"]["tg_url"].ToString();
|
||||
ImageShareQRcodeMtgTgIpv4.Source = CreateQRCode(TextBoxURLMtgTgIpv4.Text, $"{configSavePath}\\QRIpv4Tg.bmp");
|
||||
using (StreamWriter sw = new StreamWriter($"{configSavePath}\\urlIpv4Tg.txt"))
|
||||
{
|
||||
sw.WriteLine(TextBoxURLMtgTgIpv4.Text);
|
||||
}
|
||||
|
||||
TextBoxURLMtgTmeIpv4.Text = jObjectJson["ipv4"]["tme_url"].ToString();
|
||||
ImageShareQRcodeMtgTmeIpv4.Source = CreateQRCode(TextBoxURLMtgTmeIpv4.Text, $"{configSavePath}\\QRIpv4Tme.bmp");
|
||||
using (StreamWriter sw = new StreamWriter($"{configSavePath}\\urlIpv4Tme.txt"))
|
||||
{
|
||||
sw.WriteLine(TextBoxURLMtgTmeIpv4.Text);
|
||||
}
|
||||
RadioButtonMtgIpv4.IsChecked = true;
|
||||
}
|
||||
|
||||
TextBoxURLMtgTmeIpv4.Text = jObjectJson["ipv4"]["tme_url"].ToString();
|
||||
ImageShareQRcodeMtgTmeIpv4.Source = CreateQRCode(TextBoxURLMtgTmeIpv4.Text, $"{configSavePath}\\QRIpv4Tme.bmp");
|
||||
using (StreamWriter sw = new StreamWriter($"{configSavePath}\\urlIpv4Tme.txt"))
|
||||
else
|
||||
{
|
||||
sw.WriteLine(TextBoxURLMtgTmeIpv4.Text);
|
||||
RadioButtonMtgIpv4.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
if (jObjectJson["ipv6"]["tg_url"].ToString().Contains("nil") == false)
|
||||
@ -611,24 +615,19 @@ namespace ProxySU
|
||||
{
|
||||
sw.WriteLine(TextBoxURLMtgTmeIpv6.Text);
|
||||
}
|
||||
RadioButtonMtgIpv6.IsChecked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RadioButtonMtgIpv6.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
RadioButtonMtgIpv4.IsChecked = true;
|
||||
|
||||
|
||||
using (StreamWriter sw = new StreamWriter($"{configSavePath}\\mtproto_info.json"))
|
||||
{
|
||||
sw.Write(MainWindow.ReceiveConfigurationParameters[9].ToString());
|
||||
}
|
||||
|
||||
//}
|
||||
//if (File.Exists(@"mtproto_config\mtproto_info.json"))
|
||||
//{
|
||||
// File.Move(@"mtproto_config\mtproto_info.json", $"{configSavePath}\\mtproto_info.json");
|
||||
// //File.Delete(@"config\config.json");//删除该文件
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,6 +283,8 @@
|
||||
<sys:String x:Key="DisplayInstallInfo_TimeOK">The time difference meets the requirements, OK!</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_TestDomainResolve">is checking whether the domain name is resolved to the IP of the current VPS...</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_OnlyIpv6HostDetect">is detecting whether it is a pure ipv6 host...</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_FindFastestSetUpNat64">Finding the fastest Nat64 gateway...</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_FindFastestNat64AsIs">The fastest Nat64 gateway of the current host is:</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_SetUpNat64">Nat64 gateway is being set up......</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_DeleteSetUpNat64">Nat64 gateway is being deleted...</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_DomainResolveOK">The resolution is correct! OK!</sys:String>
|
||||
|
@ -288,6 +288,8 @@
|
||||
<sys:String x:Key="DisplayInstallInfo_TimeOK">时间差符合要求,OK!</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_TestDomainResolve">正在检测域名是否解析到当前VPS的IP上......</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_OnlyIpv6HostDetect">正在检测是否为纯ipv6主机......</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_FindFastestSetUpNat64">正在查找最快的Nat64网关......</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_FindFastestNat64AsIs">当前主机最快的Nat64网关为:</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_SetUpNat64">正在设置Nat64网关......</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_DeleteSetUpNat64">正在删除Nat64网关......</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_DomainResolveOK">解析正确!OK!</sys:String>
|
||||
|
@ -283,6 +283,8 @@
|
||||
<sys:String x:Key="DisplayInstallInfo_TimeOK">時間差符合要求,OK!</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_TestDomainResolve">正在檢測域名是否解析到當前VPS的IP上......</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_OnlyIpv6HostDetect">正在檢測是否為純ipv6主機......</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_FindFastestSetUpNat64">正在查找最快的Nat64網關......</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_FindFastestNat64AsIs">當前主機最快的Nat64網關為:</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_SetUpNat64">正在設置Nat64網關......</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_DeleteSetUpNat64">正在刪除Nat64網關......</sys:String>
|
||||
<sys:String x:Key="DisplayInstallInfo_DomainResolveOK">解析正確! OK!</sys:String>
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user