添加项目文件。

This commit is contained in:
jl
2023-01-13 15:30:20 +08:00
parent 40ed216831
commit bf208bde56
834 changed files with 470902 additions and 0 deletions

66
Common/PingHelper.cs Normal file
View File

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
namespace Epost.Common
{
public class PingHelper
{
public bool pingSender(string ip, int time)
{
Ping ping = new Ping();
PingReply reply = ping.Send(ip, time);//第一个参数为ip地址第二个参数为ping的时间 120
if (reply.Status == IPStatus.Success)
{
return true;
//ping的通
}
else
{
return false;
//ping不通
}
}
public void getmac()
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
//远程服务器ip
string remoteHostNameAddress = "192.168.3.137";
//构造Ping实例
Ping pingSender = new Ping();
//Ping选项设置
PingOptions options = new PingOptions();
options.DontFragment = true;
//测试数据
string data = "test data abcabc";
byte[] buffer = Encoding.ASCII.GetBytes(data);
//设置超时时间
int timeout = 120;
//调用同步send方法发送数据将返回结果保存至PingReply实例
PingReply reply = pingSender.Send(remoteHostNameAddress, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
foreach (NetworkInterface adapter in adapters)
{
string address = "答复的主机地址:" + reply.Address.ToString();
string RoundtripTime = "往返时间:" + reply.RoundtripTime;
string Ttl = "生存时间TTL" + reply.Options.Ttl;
string GetPhysicalAddress = "MAC地址" + adapter.GetPhysicalAddress();
}
}
else
{
}
}
}
}