QR_CODE(port 調整)管理員權限調整
This commit is contained in:
parent
339df0c183
commit
3284cce631
@ -54,15 +54,23 @@ namespace DualScreenDemo
|
||||
externalAddress = File.ReadAllText(serverAddressFilePath).Trim();
|
||||
Console.WriteLine("External address: " + externalAddress);
|
||||
}
|
||||
|
||||
// 启动服务器的逻辑
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: External address file not found. Using local address only.");
|
||||
}
|
||||
// 創建一個 HttpListener 來監聽 HTTP 請求
|
||||
HttpListener listener = new HttpListener();
|
||||
|
||||
// 添加本地地址前缀
|
||||
|
||||
// 構造本地地址的 URL 前綴(包含協議、地址和端口)
|
||||
string localPrefix = String.Format("http://{0}:{1}/", localAddress, port);
|
||||
|
||||
// 在控制台輸出添加的本地前綴,方便調試
|
||||
Console.WriteLine("Adding local prefix: " + localPrefix);
|
||||
|
||||
// 將本地前綴添加到 HttpListener,使其監聽該 URL
|
||||
listener.Prefixes.Add(localPrefix);
|
||||
|
||||
|
||||
// 如果有外网地址,也添加外网地址前缀
|
||||
if (!string.IsNullOrEmpty(externalAddress))
|
||||
{
|
||||
@ -70,7 +78,9 @@ namespace DualScreenDemo
|
||||
// 外網 IP 和 port 調整
|
||||
string[] parts = externalAddress.Split(':');
|
||||
string host = parts[0];
|
||||
int externalPort = parts.Length > 1 ? int.Parse(parts[1]) : port;
|
||||
string hostName = System.Net.Dns.GetHostName();
|
||||
string externalPort = '1' + hostName.Substring(Math.Max(2, hostName.Length - 20));
|
||||
//int externalPort = parts.Length > 1 ? int.Parse(parts[1]) : port;
|
||||
|
||||
string externalPrefix = String.Format("http://{0}:{1}/", host, externalPort);
|
||||
Console.WriteLine("Adding external prefix: " + externalPrefix);
|
||||
@ -87,12 +97,16 @@ namespace DualScreenDemo
|
||||
|
||||
// 生成两个二维码内容
|
||||
string localQrContent = String.Format("http://{0}:{1}/{2}/windows.html", localAddress, port, randomFolderName);
|
||||
// string localQrContent = String.Format("http://{0}:{1}/{2}/windows.html", "ss.net.dnsnet.cc", 1102, randomFolderName);
|
||||
|
||||
// 修改外网二维码内容生成
|
||||
|
||||
string externalQrContent = !string.IsNullOrEmpty(externalAddress) ?
|
||||
String.Format("http://{0}/{1}/windows.html", externalAddress, randomFolderName) :
|
||||
localQrContent;
|
||||
|
||||
|
||||
|
||||
Console.WriteLine("external QR Content : " + externalQrContent);
|
||||
// 生成二维码(这里使用外网地址的二维码,因为通常外网地址更有用)
|
||||
string qrImagePath = GenerateQRCode(externalQrContent, Path.Combine(baseDirectory, randomFolderName, "qrcode.png"));
|
||||
|
||||
|
10
app.manifest
Normal file
10
app.manifest
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
|
||||
<security>
|
||||
<requestedPrivileges>
|
||||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
</assembly>
|
Reference in New Issue
Block a user