-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
150 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Bilibili.Settings; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.NetworkInformation; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BilibiliLiveTools.Common | ||
{ | ||
public class NetworkTools | ||
{ | ||
private static readonly List<string> _hosts = new List<string>() | ||
{ | ||
"114.114.114.114", | ||
"223.5.5.5", | ||
"1.2.4.8" | ||
}; | ||
|
||
/// <summary> | ||
/// 通过Ping验证网络是否断开 | ||
/// </summary> | ||
/// <returns></returns> | ||
public static async Task<bool> NetworkCheck() | ||
{ | ||
try | ||
{ | ||
Ping ping = new Ping(); | ||
PingOptions options = new PingOptions | ||
{ | ||
DontFragment = true | ||
}; | ||
foreach (var item in _hosts) | ||
{ | ||
PingReply reply = await ping.SendPingAsync(item, 1024); | ||
if (reply.Status == IPStatus.Success) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
catch(Exception ex) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters