public static string GeoIp(string ipStr) { WebClient webClient = new WebClient { Proxy = MWebProxy, Headers = { ["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.2767.0 Safari/537.36" } }; string locStr = webClient.DownloadString($"https://api.ip.sb/geoip/{ipStr}"); JsonValue locDataJson = Json.Parse(locStr); string addr = locDataJson.AsObjectGetString("country"); if (!string.IsNullOrWhiteSpace(locDataJson.AsObjectGetString("city"))) { addr += " " + locDataJson.AsObjectGetString("city"); } if (!string.IsNullOrWhiteSpace(locDataJson.AsObjectGetString("organization"))) { addr += " / " + locDataJson.AsObjectGetString("organization"); } return(addr); }
public static void ReadConfig(string path) { JsonValue configJson = Json.Parse(File.ReadAllText(path)); try { SecondDnsIp = IPAddress.Parse(configJson.AsObjectGetString("SecondDns")); } catch { SecondDnsIp = IPAddress.Parse("1.1.1.1"); } ListenIp = IPAddress.Parse(configJson.AsObjectGetString("Listen")); BlackListEnable = configJson.AsObjectGetBool("BlackList"); WhiteListEnable = configJson.AsObjectGetBool("RewriteList"); ProxyEnable = configJson.AsObjectGetBool("ProxyEnable"); EDnsCustomize = configJson.AsObjectGetBool("EDnsCustomize"); DebugLog = configJson.AsObjectGetBool("DebugLog"); HttpsDnsUrl = configJson.AsObjectGetString("HttpsDns").Trim(); if (EDnsCustomize) { EDnsIp = IPAddress.Parse(configJson.AsObjectGetString("EDnsClientIp")); } if (ProxyEnable) { WProxy = new WebProxy(configJson.AsObjectGetString("Proxy")); } }
public static string GeoIpLocal(string ipStr) { string locStr = new WebClient().DownloadString(IsIp(ipStr) ? $"https://api.ip.sb/geoip/{ipStr}" : $"https://api.ip.sb/geoip/{Dns.GetHostAddresses(ipStr)[0]}"); JsonValue json = Json.Parse(locStr); return(json.AsObjectGetString("country_code") + ", " + json.AsObjectGetString("organization")); }
public static string GeoIpLocal(string ipStr, bool onlyCountryCode = false) { try { string locStr = new WebClient().DownloadString(IsIp(ipStr) ? $"{UrlSettings.GeoIpApi}{ipStr}": $"{UrlSettings.GeoIpApi}{Dns.GetHostAddresses(ipStr)[0]}"); JsonValue json = Json.Parse(locStr); string countryCode; string organization; if (locStr.Contains("\"country_code\"")) { countryCode = json.AsObjectGetString("country_code"); } else if (locStr.Contains("\"countryCode\"")) { countryCode = json.AsObjectGetString("countryCode"); } else { countryCode = "Unknown"; } if (locStr.Contains("\"organization\"")) { organization = json.AsObjectGetString("organization"); } else if (locStr.Contains("\"as\"")) { organization = json.AsObjectGetString("as"); } else if (locStr.Contains("\"org\"")) { organization = json.AsObjectGetString("org"); } else { organization = ""; } if (onlyCountryCode) { return(countryCode); } return(countryCode + " " + organization); } catch (Exception e) { MyTools.BgwLog(@"| DownloadString failed : " + e); return(null); } }
public static string GeoIpLocal(string ipStr) { try { string locStr = new WebClient().DownloadString(IsIp(ipStr) ? $"https://api.ip.sb/geoip/{ipStr}" : $"https://api.ip.sb/geoip/{Dns.GetHostAddresses(ipStr)[0]}"); JsonValue json = Json.Parse(locStr); return(json.AsObjectGetString("country_code") + ", " + json.AsObjectGetString("organization")); } catch (Exception e) { MyTools.BgwLog(@"| DownloadString failed : " + e); return(null); } }
public static string GeoIsp(string ipStr) { string getIpStr = new WebClient().DownloadString($"http://ip.taobao.com/service/getIpInfo.php?ip={ipStr}"); JsonValue ipJson = Json.Parse(getIpStr).AsObjectGet("data"); return(Encoding.UTF8.GetString(Encoding.Default.GetBytes(ipJson.AsObjectGetString("city") + ipJson.AsObjectGetString("isp"))).Replace("X", "")); }
public static void ReadConfig(string path) { string configStr = File.ReadAllText(path); JsonValue configJson = Json.Parse(configStr); if (configStr.Contains("\"GeoIPAPI\"")) { GeoIpApi = configJson.AsObjectGetString("GeoIPAPI"); } if (configStr.Contains("\"WhatMyIPAPI\"")) { WhatMyIpApi = configJson.AsObjectGetString("WhatMyIPAPI"); } if (configStr.Contains("\"DNSList\"")) { MDnsList = configJson.AsObjectGetString("DNSList"); } if (configStr.Contains("\"DoHList\"")) { MDohList = configJson.AsObjectGetString("DoHList"); } }
public static void ReadConfig(string path) { string configStr = File.ReadAllText(path); JsonValue configJson = Json.Parse(configStr); if (configStr.Contains("\"SecondDns\"")) { SecondDnsIp = IPAddress.Parse(configJson.AsObjectGetString("SecondDns")); } if (configStr.Contains("\"SecondHttpsDns\"")) { SecondHttpsDnsUrl = configJson.AsObjectGetString("SecondHttpsDns"); } if (configStr.Contains("\"EnableDnsMessage\"")) { DnsMsgEnable = configJson.AsObjectGetBool("EnableDnsMessage"); } if (configStr.Contains("\"EnableDnsCache\"")) { DnsCacheEnable = configJson.AsObjectGetBool("EnableDnsCache"); } if (configStr.Contains("\"EnableHttp2\"")) { Http2Enable = configJson.AsObjectGetBool("EnableHttp2"); } if (configStr.Contains("\"EnableAutoCleanLog\"")) { AutoCleanLogEnable = configJson.AsObjectGetBool("EnableAutoCleanLog"); } if (configStr.Contains("\"Port\"")) { ListenPort = configJson.AsObjectGetInt("Port", 53); } if (configStr.Contains("\"ChinaList\"")) { ChinaListEnable = configJson.AsObjectGetBool("ChinaList"); } ListenIp = IPAddress.Parse(configJson.AsObjectGetString("Listen")); BlackListEnable = configJson.AsObjectGetBool("BlackList"); WhiteListEnable = configJson.AsObjectGetBool("RewriteList"); ProxyEnable = configJson.AsObjectGetBool("ProxyEnable"); EDnsCustomize = configJson.AsObjectGetBool("EDnsCustomize"); DebugLog = configJson.AsObjectGetBool("DebugLog"); HttpsDnsUrl = configJson.AsObjectGetString("HttpsDns").Trim(); if (EDnsCustomize) { EDnsIp = IPAddress.Parse(configJson.AsObjectGetString("EDnsClientIp")); } if (ProxyEnable) { WProxy = new WebProxy(configJson.AsObjectGetString("Proxy")); } }
public static string GeoIpZXv6(string ipStr) { WebClient webClient = new WebClient { Proxy = MWebProxy, Headers = { ["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.2767.0 Safari/537.36" } }; string locStr = webClient.DownloadString($"http://ip.zxinc.org/api.php?type=json&ip={ipStr}"); JsonValue locDataJson = Json.Parse(locStr).AsObjectGet("data"); string addrLocationr = locDataJson.AsObjectGetString("location"); return(addrLocationr); }
public static void ReadConfig(string path) { string configStr = File.ReadAllText(path); JsonValue configJson = Json.Parse(configStr); if (configStr.Contains("\"SecondDns\"")) { SecondDnsIp = IPAddress.Parse(configJson.AsObjectGetString("SecondDns")); } if (configStr.Contains("\"SecondHttpsDns\"")) { SecondHttpsDnsUrl = configJson.AsObjectGetString("SecondHttpsDns"); } if (configStr.Contains("\"EnableDnsMessage\"")) { DnsMsgEnable = configJson.AsObjectGetBool("EnableDnsMessage"); } if (configStr.Contains("\"EnableDnsCache\"")) { DnsCacheEnable = configJson.AsObjectGetBool("EnableDnsCache"); } if (configStr.Contains("\"EnableHttp2\"")) { Http2Enable = configJson.AsObjectGetBool("EnableHttp2"); } if (configStr.Contains("\"EnableAutoCleanLog\"")) { AutoCleanLogEnable = configJson.AsObjectGetBool("EnableAutoCleanLog"); } if (configStr.Contains("\"Port\"")) { ListenPort = configJson.AsObjectGetInt("Port", 53); } if (configStr.Contains("\"ChinaList\"")) { ChinaListEnable = configJson.AsObjectGetBool("ChinaList"); } if (configStr.Contains("\"StartupOverDoH\"")) { StartupOverDoH = configJson.AsObjectGetBool("StartupOverDoH"); } if (configStr.Contains("\"AllowSelfSignedCert\"")) { AllowSelfSignedCert = configJson.AsObjectGetBool("AllowSelfSignedCert"); } if (configStr.Contains("\"AllowAutoRedirect\"")) { AllowAutoRedirect = configJson.AsObjectGetBool("AllowAutoRedirect"); } if (configStr.Contains("\"HTTPStatusNotify\"")) { HTTPStatusNotify = configJson.AsObjectGetBool("HTTPStatusNotify"); } if (configStr.Contains("\"Ipv6Disable\"")) { Ipv6Disable = configJson.AsObjectGetBool("Ipv6Disable"); } if (configStr.Contains("\"Ipv4Disable\"")) { Ipv4Disable = configJson.AsObjectGetBool("Ipv4Disable"); } if (configStr.Contains("\"TTLRewrite\"")) { TtlRewrite = configJson.AsObjectGetBool("TTLRewrite"); } if (configStr.Contains("\"TTLMinTime\"")) { TtlMinTime = configJson.AsObjectGetInt("TTLMinTime"); } ListenIp = IPAddress.Parse(configJson.AsObjectGetString("Listen")); BlackListEnable = configJson.AsObjectGetBool("BlackList"); WhiteListEnable = configJson.AsObjectGetBool("RewriteList"); ProxyEnable = configJson.AsObjectGetBool("ProxyEnable"); EDnsCustomize = configJson.AsObjectGetBool("EDnsCustomize"); DebugLog = configJson.AsObjectGetBool("DebugLog"); HttpsDnsUrl = configJson.AsObjectGetString("HttpsDns").Trim(); if (EDnsCustomize) { EDnsIp = IPAddress.Parse(configJson.AsObjectGetString("EDnsClientIp")); } if (ProxyEnable) { WProxy = new WebProxy(configJson.AsObjectGetString("Proxy")); } }
private static void ReadConfig(string path) { Console.WriteLine(@"------Read Config-------"); string jSrt = File.ReadAllText(path); JsonValue configJson = Json.Parse(jSrt); ADnsSetting.ListenIp = jSrt.Contains("Listen") ? IPAddress.Parse(configJson.AsObjectGetString("Listen")) : IPAddress.Any; ADnsSetting.BlackListEnable = jSrt.Contains("BlackList") && configJson.AsObjectGetBool("BlackList"); ADnsSetting.ChinaListEnable = jSrt.Contains("ChinaList") && configJson.AsObjectGetBool("ChinaList"); ADnsSetting.WhiteListEnable = jSrt.Contains("RewriteList") && configJson.AsObjectGetBool("RewriteList"); ADnsSetting.ProxyEnable = jSrt.Contains("ProxyEnable") && configJson.AsObjectGetBool("ProxyEnable"); ADnsSetting.IPv6Enable = !jSrt.Contains("IPv6Enable") || configJson.AsObjectGetBool("IPv6Enable"); ADnsSetting.AllowSelfSignedCert = jSrt.Contains("AllowSelfSignedCert") && configJson.AsObjectGetBool("AllowSelfSignedCert"); ADnsSetting.EDnsCustomize = jSrt.Contains("EDnsCustomize") && configJson.AsObjectGetBool("EDnsCustomize"); ADnsSetting.DebugLog = jSrt.Contains("DebugLog") && configJson.AsObjectGetBool("DebugLog"); ADnsSetting.EDnsIp = jSrt.Contains("EDnsClientIp") ? IPAddress.Parse(configJson.AsObjectGetString("EDnsClientIp")) : IPAddress.Any; if (configJson.ToString().Contains("HttpsDns")) { ADnsSetting.HttpsDnsUrl = configJson.AsObjectGetString("HttpsDns"); if (string.IsNullOrEmpty(ADnsSetting.HttpsDnsUrl)) { ADnsSetting.HttpsDnsUrl = "https://1.0.0.1/dns-query"; } } else { ADnsSetting.HttpsDnsUrl = "https://1.0.0.1/dns-query"; } Console.WriteLine(@"Listen : " + ADnsSetting.ListenIp); Console.WriteLine(@"BlackList : " + ADnsSetting.BlackListEnable); Console.WriteLine(@"RewriteList : " + ADnsSetting.WhiteListEnable); Console.WriteLine(@"ChinaList : " + ADnsSetting.WhiteListEnable); Console.WriteLine(@"ProxyEnable : " + ADnsSetting.ProxyEnable); Console.WriteLine(@"DebugLog : " + ADnsSetting.DebugLog); Console.WriteLine(@"EDnsPrivacy : " + ADnsSetting.EDnsCustomize); Console.WriteLine(@"EDnsClient : " + ADnsSetting.EDnsIp); Console.WriteLine(@"HttpsDns : " + ADnsSetting.HttpsDnsUrl); if (ADnsSetting.AllowSelfSignedCert) { Console.WriteLine(@"AllowSelfSignedCert : " + ADnsSetting.AllowSelfSignedCert); } if (ADnsSetting.ProxyEnable) { ADnsSetting.WProxy = new WebProxy(configJson.AsObjectGetString("Proxy")); Console.WriteLine(@"ProxyServer : " + configJson.AsObjectGetString("Proxy")); } }
private static void ReadConfig(string path) { Console.WriteLine(@"------Read Config-------"); JsonValue configJson = Json.Parse(File.ReadAllText(path)); try { ADnsSetting.ListenIp = IPAddress.Parse(configJson.AsObjectGetString("Listen")); } catch { ADnsSetting.ListenIp = IPAddress.Any; } try { ADnsSetting.BlackListEnable = configJson.AsObjectGetBool("BlackList"); } catch { ADnsSetting.BlackListEnable = false; } try { ADnsSetting.WhiteListEnable = configJson.AsObjectGetBool("RewriteList"); } catch { ADnsSetting.WhiteListEnable = false; } try { ADnsSetting.ProxyEnable = configJson.AsObjectGetBool("ProxyEnable"); } catch { ADnsSetting.ProxyEnable = false; } try { ADnsSetting.IPv6Enable = configJson.AsObjectGetBool("IPv6Enable"); } catch { ADnsSetting.IPv6Enable = true; } try { ADnsSetting.EDnsCustomize = configJson.AsObjectGetBool("EDnsCustomize"); } catch { ADnsSetting.EDnsCustomize = false; } try { ADnsSetting.DebugLog = configJson.AsObjectGetBool("DebugLog"); } catch { ADnsSetting.DebugLog = false; } try { ADnsSetting.EDnsIp = IPAddress.Parse(configJson.AsObjectGetString("EDnsClient")); } catch { ADnsSetting.EDnsIp = IPAddress.Any; } try { ADnsSetting.HttpsDnsUrl = configJson.AsObjectGetString("HttpsDns"); if (string.IsNullOrEmpty(ADnsSetting.HttpsDnsUrl)) { ADnsSetting.HttpsDnsUrl = "https://1.0.0.1/dns-query"; } } catch { ADnsSetting.HttpsDnsUrl = "https://1.0.0.1/dns-query"; } Console.WriteLine(@"Listen : " + ADnsSetting.ListenIp); Console.WriteLine(@"BlackList : " + ADnsSetting.BlackListEnable); Console.WriteLine(@"RewriteList : " + ADnsSetting.WhiteListEnable); Console.WriteLine(@"ProxyEnable : " + ADnsSetting.ProxyEnable); Console.WriteLine(@"DebugLog : " + ADnsSetting.DebugLog); Console.WriteLine(@"EDnsPrivacy : " + ADnsSetting.EDnsCustomize); Console.WriteLine(@"EDnsClient : " + ADnsSetting.EDnsIp); Console.WriteLine(@"HttpsDns : " + ADnsSetting.HttpsDnsUrl); if (ADnsSetting.ProxyEnable) { ADnsSetting.WProxy = new WebProxy(configJson.AsObjectGetString("Proxy")); Console.WriteLine(@"ProxyServer : " + configJson.AsObjectGetString("Proxy")); } }