using System; using System.Net; namespace Netch.Models.Server { public class Server { /// /// 类型 /// [Newtonsoft.Json.JsonProperty("type")] public ServerType Type; /// /// 备注 /// [Newtonsoft.Json.JsonProperty("remark")] public string Remark; /// /// 地址 /// [Newtonsoft.Json.JsonProperty("host")] public string Host; /// /// 端口 /// [Newtonsoft.Json.JsonProperty("port")] public ushort Port; /// /// 延迟 /// [Newtonsoft.Json.JsonIgnore] public int Ping = -1; /// /// 测试延迟 /// /// public void TestPing() => this.Ping = Utils.Ping.Fetch(this); /// /// 解析地址 /// /// public string Resolve() => (Utils.DNS.Fetch(this.Host) != IPAddress.Any) ? Utils.DNS.Fetch(this.Host).ToString() : this.Host; /// /// 获取备注 /// /// public override string ToString() { string name = this.Type switch { ServerType.Socks => "S5", ServerType.Shadowsocks => "SS", ServerType.ShadowsocksR => "SR", ServerType.WireGuard => "WG", ServerType.Trojan => "TR", ServerType.VMess => "VM", ServerType.VLess => "VL", _ => "UN", }; return String.Format("[{0}] {1}", name, String.IsNullOrEmpty(this.Remark) ? $"{this.Host}:{this.Port}" : this.Remark); } } }