Exemplo n.º 1
0
    private string GetCountryCode(string strIPAddress)
    {
        string result = "-";

        IP2Location.IPResult  oIPResult    = new IP2Location.IPResult();
        IP2Location.Component oIP2Location = new IP2Location.Component();
        try
        {
            if (strIPAddress != "")
            {
                oIP2Location.IPDatabasePath = Server.MapPath("bin") + "/IPV6-COUNTRY-REGION-CITY.BIN"; // for both IPv4 & IPv6
                //oIP2Location.IPDatabasePath = Server.MapPath("bin") + "/IP-COUNTRY-REGION-CITY.BIN"; // for just IPv4
                // oIP2Location.IPDatabasePath = @"C:\Program Files\IP2Location\IP2LOCATION-LITE-DB1.IPV6.BIN"; // for both IPv4 & IPv6

                //Set License Path
                oIP2Location.IPLicensePath = Server.MapPath("bin") + "/License.key";

                oIPResult = oIP2Location.IPQuery(strIPAddress);
                if (oIPResult.Status.ToString() == "OK")
                {
                    result = oIPResult.CountryShort;
                }
            }
        }
        catch (Exception ex)
        {
        }
        finally
        {
            oIPResult    = null;
            oIP2Location = null;
        }
        return(result);
    }
Exemplo n.º 2
0
        public IPHeaderV4(BinaryReader binaryReader, IP2Location.Component ip2l)
        {
            try
            {
                _headerLength   = binaryReader.ReadByte();
                _headerLength <<= 4;
                _headerLength >>= 4;
                _headerLength  *= 4;

                _differentiatedServices = binaryReader.ReadByte();

                _totalLength = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                _identification = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                _flagsAndOffset = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                _timeToLive = binaryReader.ReadByte();

                _protocol = binaryReader.ReadByte();

                _checksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                SourceAddress = new ExtendedIpAddress((uint)(binaryReader.ReadInt32()), ip2l);

                DestinationAddress = new ExtendedIpAddress((uint)(binaryReader.ReadInt32()), ip2l);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "PraisedSniffer", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        public IPHeaderV6(BinaryReader binaryReader, IP2Location.Component ip2l)
        {
            _versionTrafficClassAndFlowLabel = (uint)IPAddress.NetworkToHostOrder(binaryReader.ReadInt32());

            _payloadLength = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

            _nextHeader = binaryReader.ReadByte();

            _hopLimit = binaryReader.ReadByte();

            for (int i = 0; i < 16; i++)
            {
                _sourceAddress[i] = binaryReader.ReadByte();
            }

            SourceAddress = new ExtendedIpAddress(_sourceAddress, ip2l);
            SourceAddress.ToString();

            for (int i = 0; i < 16; i++)
            {
                _destinationAddress[i] = binaryReader.ReadByte();
            }

            DestinationAddress = new ExtendedIpAddress(_destinationAddress, ip2l);
        }
 private void setMetaFields(IP2Location.Component ip2l)
 {
     if (ip2l != null)
     {
         var qr = ip2l.IPQuery(ToString());
         City      = qr.City;
         Country   = qr.CountryLong;
         Region    = qr.Region;
         Latitude  = qr.Latitude;
         Longitude = qr.Longitude;
         ZipCode   = qr.ZipCode;
         TimeZone  = qr.TimeZone;
     }
 }
        public List <String> getGeoInfo(String ip2Geo)
        {
            IP2Location.IPResult  oIPResult    = new IP2Location.IPResult();
            IP2Location.Component oIP2Location = new IP2Location.Component();

            List <String> ipInfos = new List <string>();

            try {
                oIP2Location.IPDatabasePath = Environment.CurrentDirectory + @"\\Location DB\\IP2LOCATION-LITE-DB11.BIN";
                oIPResult = oIP2Location.IPQuery(ip2Geo);

                if (oIPResult.Status.ToString().Equals("OK"))
                {
                    ipInfos.Add(oIPResult.CountryLong);
                    ipInfos.Add(oIPResult.City);
                    ipInfos.Add(oIPResult.Region);
                    ipInfos.Add(oIPResult.ZipCode);
                    ipInfos.Add(oIPResult.TimeZone);

                    return(ipInfos);
                }

                else
                {
                    List <String> errorLists = new List <string>();

                    errorLists.Add(oIPResult.Status.ToString());
                    errorLists.Add(oIPResult.Status.ToString());
                    errorLists.Add(oIPResult.Status.ToString());
                    errorLists.Add(oIPResult.Status.ToString());
                    errorLists.Add(oIPResult.Status.ToString());

                    return(errorLists);
                }
            }
            catch
            {
                List <String> errorListse = new List <string>();

                errorListse.Add("No Data in DB");
                errorListse.Add("No Data in DB");
                errorListse.Add("No Data in DB");
                errorListse.Add("No Data in DB");
                errorListse.Add("No Data in DB");

                return(errorListse);
            }
        }
Exemplo n.º 6
0
        void LoadIp2l(string binFile)
        {
            IP2Location.Component ip2l;
            if (binFile == "" || binFile == null)
            {
                using (OpenFileDialog openFileDialog = new OpenFileDialog())
                {
                    openFileDialog.Filter           = "IP2L Database files (*.BIN)|*.BIN|All files (*.*)|*.*";
                    openFileDialog.FilterIndex      = 1;
                    openFileDialog.RestoreDirectory = true;

                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        binFile = openFileDialog.FileName;
                    }
                }
            }

            if (binFile != "" && binFile != null)
            {
                ip2l = new IP2Location.Component();
                ip2l.UseMemoryMappedFile = true;
                ip2l.IPDatabasePath      = binFile;
                if (ip2l.LoadBIN())
                {
                    this.ip2l     = ip2l;
                    textBox1.Text = binFile;
                    Properties.Settings.Default.DbFile = binFile;
                    Properties.Settings.Default.Save();
                }
                else
                {
                    MessageBox.Show("Não foi possível abrir o arquivo do banco de dados", "Falha", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Properties.Settings.Default.DbFile = "";
                    Properties.Settings.Default.Save();
                }
            }

            WarnIp2lNotLoadeded();
        }
Exemplo n.º 7
0
        public static GeoLocation GetGeoLocation(string strIPAddress)
        {
            IP2Location.IPResult  oIPResult    = new IP2Location.IPResult();
            IP2Location.Component oIP2Location = new IP2Location.Component();
            try
            {
                if (!string.IsNullOrEmpty(strIPAddress))
                {
                    oIP2Location.IPDatabasePath = GetGeoDBLocation();
                    oIPResult = oIP2Location.IPQuery(strIPAddress);
                    switch (oIPResult.Status.ToString())
                    {
                    case "OK":

                        return(new GeoLocation()
                        {
                            City = oIPResult.City,
                            CountryShort = oIPResult.CountryShort,
                            CountryLong = oIPResult.CountryLong,
                            ZipCode = oIPResult.ZipCode,
                            DomainName = oIPResult.DomainName,
                            InternetServiceProvider = oIPResult.InternetServiceProvider,
                            Latitude = oIPResult.Latitude.ToString(),
                            Longitude = oIPResult.Longitude.ToString()
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            finally
            {
                oIPResult    = null;
                oIP2Location = null;
            }
            return(null);
        }
Exemplo n.º 8
0
    static public string GetCountryCode(string strIPAddress)
    {
        if (DB_PATH == null)
        {
            string path = HttpContext.Current.Server.MapPath("~/App_Data");
            DB_PATH  = path + "/IP-COUNTRY.BIN";
            LIC_PATH = path + "/License.key";
        }

        IP2Location.IPResult  oIPResult    = new IP2Location.IPResult();
        IP2Location.Component oIP2Location = new IP2Location.Component();
        try
        {
            //Set Database Paths
            oIP2Location.IPDatabasePath = DB_PATH;
            oIP2Location.IPLicensePath  = LIC_PATH;

            oIPResult = oIP2Location.IPQuery(strIPAddress);
            switch (oIPResult.Status.ToString())
            {
            case "OK":
                return(oIPResult.CountryShort);

            default:
                return(null);
            }
        }
        catch (Exception ex)
        {
            throw new ApiExitException(ex.Message);
        }
        finally
        {
            oIPResult    = null;
            oIP2Location = null;
        }
    }
 public ExtendedIpAddress(byte[] address, long scopeid, IP2Location.Component ip2l) : base(address, scopeid)
 {
     setMetaFields(ip2l);
 }
Exemplo n.º 10
0
 public ExtendedIpAddress(long newAddress, IP2Location.Component ip2l) : base(newAddress)
 {
     setMetaFields(ip2l);
 }