Exemple #1
0
        private void btnInfo_Click(object sender, EventArgs e)
        {
            SxGeo.OpenDB();
            SxGeo.CloseDB();
            SxGeoHeader Header = SxGeo.GetHeader();

            if (Header.PackFormat == null)
            {
                Header.PackFormat = string.Empty;
            }

            frmInfo fInfo = new frmInfo();

            fInfo.Header = Header;
            fInfo.ShowDialog();
        }
        public Dictionary <string, object> GetIPInfo(string IP)
        {
            Dictionary <string, object> buf = new Dictionary <string, object>();
            string NormalForm = string.Empty;
            string InputIP    = string.Empty;

            if (!IPConverter.IsIP(IP))
            {
                buf.Add("ip", IP);
                buf.Add("status", "ERROR: Not valid IP address");
                return(buf);
            }
            SxGeoDB db = new SxGeoDB(DatabasePath);

            db.DatabaseMode = SxGeoMode.FileMode;
            if (!db.OpenDB())
            {
                buf.Add("status", "ERROR: " + db.ErrorMessage);
                return(buf);
            }

            NormalForm = IPConverter.ToStandForm(IP);
            if (NormalForm != IP)
            {
                InputIP = IP;
                IP      = NormalForm;
            }

            string spec = CheckSpecDiaps(IP);

            if (spec != string.Empty)
            {
                buf.Add("ip", IP);
                if (InputIP != string.Empty)
                {
                    buf.Add("input_ip", InputIP);
                }
                buf.Add("status", "WARNING: " + spec);
                return(buf);
            }

            buf = db.GetIPInfo(IP, SxGeoInfoType.FullInfo);
            if (buf == null)
            {
                buf = new Dictionary <string, object>();
                buf.Add("ip", IP);
                if (InputIP != string.Empty)
                {
                    buf.Add("input_ip", InputIP);
                }
                buf.Add("status", db.ErrorMessage);
                return(buf);
            }

            if (InputIP != string.Empty)
            {
                buf.Add("input_ip", InputIP);
            }
            buf.Add("status", "OK");
            db.CloseDB();

            return(buf);
        }