88using NextTrace ;
99using System . Net ;
1010using Newtonsoft . Json ;
11+ using System . Runtime . InteropServices ;
1112
1213namespace OpenTrace
1314{
@@ -107,7 +108,8 @@ public MainForm()
107108
108109 mapWebView = new WebView
109110 {
110- Url = new Uri ( "https://lbs.baidu.com/jsdemo/demo/webgl0_0.htm" )
111+ Url = new Uri ( "https://lbs.baidu.com/jsdemo/demo/webgl0_0.htm" ) ,
112+
111113 } ;
112114
113115 // 绑定控件事件
@@ -118,7 +120,7 @@ public MainForm()
118120 tracerouteGridView . MouseUp += Dragging_MouseUp ;
119121 tracerouteGridView . SelectedRowsChanged += TracerouteGridView_SelectedRowsChanged ;
120122 startTracerouteButton . Click += StartTracerouteButton_Click ;
121- HostInputBox . KeyUp += HostInputBox_KeyUp ;
123+ HostInputBox . KeyDown += HostInputBox_KeyDown ;
122124 HostInputBox . TextChanged += HostInputBox_TextChanged ;
123125 MTRMode . CheckedChanged += MTRMode_CheckedChanged ;
124126
@@ -184,9 +186,9 @@ private void MTRMode_CheckedChanged(object sender, EventArgs e)
184186 }
185187 }
186188
187- private void HostInputBox_KeyUp ( object sender , KeyEventArgs e )
189+ private void HostInputBox_KeyDown ( object sender , KeyEventArgs e )
188190 {
189- if ( e . Key == Keys . Enter )
191+ if ( e . Key == Keys . Enter )
190192 {
191193 if ( CurrentInstance != null ) StopTraceroute ( ) ;
192194 StartTracerouteButton_Click ( sender , e ) ;
@@ -200,6 +202,11 @@ private void TracerouteGridView_SelectedRowsChanged(object sender, EventArgs e)
200202
201203 private void StartTracerouteButton_Click ( object sender , EventArgs e )
202204 {
205+ if ( protocolSelection . SelectedValue . ToString ( ) != "ICMP" && RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
206+ {
207+ MessageBox . Show ( Resources . WINDOWS_TCP_UDP_UNSUPPORTED ) ;
208+ return ;
209+ }
203210 if ( CurrentInstance != null )
204211 {
205212 StopTraceroute ( ) ;
@@ -265,6 +272,7 @@ private void StartTracerouteButton_Click(object sender, EventArgs e)
265272 HostInputBox . Text = uri . Host ;
266273 }
267274 // 需要域名解析
275+ Title = Resources . APPTITLE + ": " + HostInputBox . Text ;
268276 IPAddress [ ] resolvedAddresses = Dns . GetHostAddresses ( HostInputBox . Text ) ;
269277 if ( resolvedAddresses . Length > 1 )
270278 {
@@ -287,11 +295,13 @@ private void StartTracerouteButton_Click(object sender, EventArgs e)
287295 catch ( System . Net . Sockets . SocketException )
288296 {
289297 MessageBox . Show ( string . Format ( Resources . NAME_NOT_RESOLVED , HostInputBox . Text ) , MessageBoxType . Warning ) ;
298+ Title = Resources . APPTITLE ;
290299 return ;
291300 }
292301 catch ( Exception exception )
293302 {
294303 MessageBox . Show ( exception . Message , MessageBoxType . Error ) ;
304+ Title = Resources . APPTITLE ;
295305 return ;
296306 }
297307 }
@@ -300,6 +310,7 @@ private void StartTracerouteButton_Click(object sender, EventArgs e)
300310 HostInputBox . Items . Insert ( 0 , new ListItem { Text = HostInputBox . Text } ) ;
301311 CurrentInstance = instance ;
302312 startTracerouteButton . Text = Resources . STOP ;
313+ int errorOutputCount = 0 ;
303314
304315 ExceptionalOutputForm exceptionalOutputForm = new ExceptionalOutputForm ( ) ;
305316
@@ -334,6 +345,14 @@ private void StartTracerouteButton_Click(object sender, EventArgs e)
334345 {
335346 exceptionalOutputForm . Visible = true ;
336347 }
348+ if ( errorOutputCount < 100 )
349+ {
350+ errorOutputCount ++ ;
351+ }
352+ else
353+ {
354+ StopTraceroute ( ) ; // 错误输出过多,强制结束
355+ }
337356 exceptionalOutputForm . AppendOutput ( e2 . Output ) ;
338357 } ) ;
339358 } ;
@@ -363,10 +382,13 @@ private void StartTracerouteButton_Click(object sender, EventArgs e)
363382 }
364383 private void StopTraceroute ( )
365384 {
366- appForceExiting = true ;
367- CurrentInstance . Kill ( ) ;
368- startTracerouteButton . Text = Resources . START ;
369- CurrentInstance = null ;
385+ if ( CurrentInstance != null )
386+ {
387+ appForceExiting = true ;
388+ CurrentInstance . Kill ( ) ;
389+ startTracerouteButton . Text = Resources . START ;
390+ CurrentInstance = null ;
391+ }
370392 }
371393
372394 /*
0 commit comments