Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C # how to automatically obtain the dynamic domain name and port of free natapp on a regular basis

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

这篇文章主要讲解了"c#怎么实现定时自动获取免费natapp的动态域名和端口",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"c#怎么实现定时自动获取免费natapp的动态域名和端口"吧!

一、关闭natapp.exe进程

KillProcess("natapp"); private static void KillProcess(string processName) { Process[] myproc = Process.GetProcesses(); foreach (Process item in myproc) { if (item.ProcessName == processName) { item.Kill(); } } }

二、删除natapp.exe运行产生的log文件

DeleteLog("log.txt");

private static void DeleteLog(string logPath) { DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory); FileInfo[] fis = di.GetFiles(); foreach (FileInfo fi in fis) { try { if (fi.Name.Contains(logPath)) { fi.Delete(); } } catch (Exception ex) { } } }

三、启动natapp.exe进程

StartNatappProcess(Environment.CurrentDirectory + "\\natapp\\natapp.exe");

private static void StartNatappProcess(string natappPath) { Process process = new Process(); process.StartInfo.FileName = natappPath; //process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; // 启动的时候最小化程序 process.Start(); Thread.Sleep(1000); }

四、解析natapp.exe运行产生的log文件

ResolveLog("log.txt");

private static void ResolveLog(string logPath) { resolveResult = new ResolveResult(); using (FileStream fs = new FileStream(logPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (StreamReader sr = new StreamReader(fs, Encoding.Default)) { StringBuilder sb = new StringBuilder(); while (!sr.EndOfStream) { sb.AppendLine(sr.ReadLine() + "

"); } string str = sb.ToString(); int x = str.IndexOf("Url"); //定位位置 string validData = str.Substring(x, 100); string[] strTmps = validData.Split('"'); string[] serverStr = strTmps[2].Split(':'); resolveResult.serverUrl = serverStr[0] + ":" + serverStr[1]; if (serverStr.Length>2) { resolveResult.serverPort = int.Parse(serverStr[2]); } resolveResult.localIP = strTmps[10].Split(':')[0]; resolveResult.localPort = int.Parse(strTmps[10].Split(':')[1]); } }

运行后的截图

Thank you for reading, the above is the content of "c#how to automatically obtain the dynamic domain name and port of free natapp on a regular basis", after learning this article, I believe everyone has a deeper understanding of how to automatically obtain the dynamic domain name and port of free natapp on a regular basis. The specific use situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report