Skip to content

Commit 064eec1

Browse files
committed
fix issue #9; add notice for windows udp/tcp tracerouting
1 parent 6968d38 commit 064eec1

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

MainForm.cs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using NextTrace;
99
using System.Net;
1010
using Newtonsoft.Json;
11+
using System.Runtime.InteropServices;
1112

1213
namespace 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
/*

Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ Would you like to download the NextTrace utility now?</value>
342342
<data name="TRACEROUTING" xml:space="preserve">
343343
<value>Tracerouting</value>
344344
</data>
345+
<data name="WINDOWS_TCP_UDP_UNSUPPORTED" xml:space="preserve">
346+
<value>TCP/UDP Traceroute is not yet supported on Windows.</value>
347+
</data>
345348
<data name="WORST" xml:space="preserve">
346349
<value>Worst</value>
347350
</data>

Properties/Resources.zh-CN.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@
336336
<data name="TRACEROUTING" xml:space="preserve">
337337
<value>路由追踪</value>
338338
</data>
339+
<data name="WINDOWS_TCP_UDP_UNSUPPORTED" xml:space="preserve">
340+
<value>Windows 暂不支持 TCP/UDP Traceroute</value>
341+
</data>
339342
<data name="WORST" xml:space="preserve">
340343
<value>最差延迟</value>
341344
</data>

javascript/baiduMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ window.opentrace = {
2929
} catch (e) {}
3030
}
3131
if (pointlygon_array.length < 2) return;
32-
var polygon = new BMapGL.Polyline(pointlygon_array, { strokeColor: "red", strokeWeight: 2, geodesic: true, strokeOpacity: 0.5 }); //创建折线
32+
var polygon = new BMapGL.Polyline(pointlygon_array, { strokeColor: "red", strokeWeight: 2, strokeOpacity: 0.5 }); //创建折线
3333
//Polyline(坐标值,{线段颜色,线段宽度,线段透明度});
3434
map.addOverlay(polygon); //添加覆盖物
3535
map.setViewport(pointlygon_array); //设置地图的中心点和缩放级别

0 commit comments

Comments
 (0)