private static void CheckAsn(AsnResponse response, string ipAddress)
 {
     Assert.Equal(1221, response.AutonomousSystemNumber);
     Assert.Equal("Telstra Pty Ltd", response.AutonomousSystemOrganization);
     Assert.Equal(ipAddress, response.IPAddress);
     Assert.Equal("1.128.0.0/11", response.Network?.ToString());
 }
Exemplo n.º 2
0
        public static string GetCnISP(AsnResponse asnResponse, CityResponse cityResponse)
        {
            var country = cityResponse.Country.IsoCode;
            var asName  = asnResponse.AutonomousSystemOrganization.ToLower();

            if (country != "CN")
            {
                return(string.Empty);
            }

            if (asName.Contains("cernet") || asName.Contains("education") || asName.Contains("research") ||
                asName.Contains("university") || asName.Contains("academy") ||
                asName.Contains("computer network information center"))
            {
                return("CE");
            }
            if (asName.Contains("mobile") || asName.Contains("cmnet") || asName.Contains("tietong") ||
                asName.Contains("railway"))
            {
                return("CM");
            }
            if (asName.Contains("unicom") || asName.Contains("cnc") ||
                asName.Contains("china169") || asName.Contains("netcom"))
            {
                return("CU");
            }
            if (asName.Contains("chinanet") || asName.Contains("telecom") || asName.Contains("no.31,jin-rong") ||
                asName.Contains("inter-exchange") || asName.Contains("ct"))
            {
                return("CT");
            }

            return(string.Empty);
        }
Exemplo n.º 3
0
        public static (AsnResponse, CityResponse) GetAsnCityValueTuple(string ipAddress)
        {
            var asn  = new AsnResponse();
            var city = new CityResponse();

            Task.WaitAll(
                Task.Run(() => asn  = GetAsnResponse(ipAddress)),
                Task.Run(() => city = GetCityResponse(ipAddress)));
            return(asn, city);
        }
Exemplo n.º 4
0
        public static List <Logfileentries> logfilesentry(string dbcountrypath, string dbasnpath, string logpath)
        {
            List <Logfileentries> logentries = new List <Logfileentries>();
            Regex          IPaddress         = new Regex(@"\b(?:\d{1,3}\.){3}\d{1,3}\b");
            Regex          Timestamp         = new Regex(@"\d{2}\/\w{3}\/\d{4}:\d{2}:\d{2}:\d{2} (\+|\-)\d{4}");
            Regex          IPandTimestamp    = new Regex(@"\b(?:\d{1,3}\.){3}\d{1,3}\b - - \[\d{2}\/\w{3}\/\d{4}:\d{2}:\d{2}:\d{2} (\+|\-)\d{4}\] ");
            DatabaseReader ipcountry         = new DatabaseReader(dbcountrypath);
            DatabaseReader ipASN             = new DatabaseReader(dbasnpath);
            string         hostname          = "";

            foreach (var line in File.ReadLines(logpath))
            {
                Logfileentries logfileentry = new Logfileentries();
                Match          iptimestamp  = IPandTimestamp.Match(line);
                Match          ipaddress    = IPaddress.Match(iptimestamp.Value);
                Match          timestamp    = Timestamp.Match(iptimestamp.Value);
                //Console.WriteLine(ipaddress.Value);
                CountryResponse countryresponse = ipcountry.Country(ipaddress.Value);
                AsnResponse     ASNresponse     = ipASN.Asn(ipaddress.Value);
                try{ hostname = Dns.GetHostEntry(ipaddress.Value).HostName; }
                catch (SocketException) {}
                if (hostname == "")
                {
                    hostname = "unknown domain";
                }
                string[] logmethod = Regex.Split(line, IPandTimestamp.ToString());
                logfileentry.Logipaddress = ipaddress.Value;
                logfileentry.Logtimestamp = timestamp.Value;
                logfileentry.Logmethod    = logmethod[2];
                logfileentry.Logcountry   = countryresponse.Country.ToString();
                logfileentry.LogASN       = ASNresponse.AutonomousSystemOrganization.ToString();
                logfileentry.LogDNS       = hostname;
                logentries.Add(logfileentry);
                //Console.WriteLine(logfileentry.Logipaddress + "||" + logfileentry.Logtimestamp + "||" + logfileentry.Logmethod + "||" + logfileentry.Logcountry + "||" + logfileentry.LogASN + "||" + logfileentry.LogDNS);
            }
            return(logentries);
        }
Exemplo n.º 5
0
 /// <summary>
 ///     Tries to lookup an <see cref="AsnResponse" /> for the specified IP address.
 /// </summary>
 /// <param name="ipAddress">The IP address.</param>
 /// <param name="response">The <see cref="AsnResponse" />.</param>
 /// <returns>A <see cref="bool" /> describing whether the IP address was found.</returns>
 public bool TryAsn(string ipAddress, out AsnResponse response)
 {
     response = Execute <AsnResponse>(ipAddress, "GeoLite2-ASN", false);
     return(response != null);
 }