public void ThreadFunction(object data) { IPResult newData = (IPResult)data; string ip = newData.ipRangeFrom; //Debug.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " Started"); bool pingable = false; Ping pinger = null; try { pinger = new Ping(); PingReply reply = pinger.Send(ip); pingable = reply.Status == IPStatus.Success; newData.Results.Add(new IPInfo() { RoundTripTime = reply.RoundtripTime.ToString(), IPAddress = ip, PingAble = pingable.ToString() }); } catch (PingException) { // Discard PingExceptions and return false; } finally { if (pinger != null) { pinger.Dispose(); } } }
public bool canShow(string ip) { string url = "http://ip.taobao.com/service/getIpInfo.php?ip=" + ip; var ret = HttpPost.Get(new Uri(url), false); if (ret != null) { string retstr = Encoding.UTF8.GetString(ret); try { IPResult result = JsonHelper.ParseFromStr <IPResult>(retstr); if (result.code == 0) { if (result.data.city_id == "110100" || result.data.city_id == "310100" || result.data.city_id == "440100" || result.data.city_id == "440300") { return(false); } else { return(true); } } } catch { } } return(false); }
private void PopulateTree(IPResult result) { TreeNode mainNode = new TreeNode("IP Informations"); // This reflection is done to speed up dev time, it's not recommended to use this in a prod app foreach (PropertyInfo p in result.GetType().GetProperties()) { if (p.PropertyType == typeof(string)) { mainNode.Nodes.Add(new TreeNode($"{p.Name}: {p.GetValue(result)}")); } else if (p.GetValue(result) != null) { TreeNode secondNode = new TreeNode(p.Name); foreach (PropertyInfo pp in p.PropertyType.GetProperties()) { if (pp.PropertyType == typeof(string)) { secondNode.Nodes.Add(new TreeNode($"{pp.Name}: {pp.GetValue(p.GetValue(result))}")); } } mainNode.Nodes.Add(secondNode); } } treeResult.Nodes.Add(mainNode); SetControlsState(true); }
public static GeoLocation GetGeoLocation(string strIPAddress) { IPResult oIPResult = new IPResult(); Component oIP2Location = new Component(); try { if (!string.IsNullOrEmpty(strIPAddress)) { oIP2Location.IPDatabasePath = GetGeoDBLocation(); oIPResult = oIP2Location.IPQuery(strIPAddress); switch (oIPResult.Status.ToString()) { case "OK": return(MapLocation(oIPResult)); } } } finally { oIPResult = null; oIP2Location = null; } return(null); }
private async void BtnRequest_Click(object sender, EventArgs e) { treeResult.Nodes.Clear(); SetControlsState(false); IPResult result = null; if (ckAsync.Checked) { if (cmbFields.SelectedIndex != 0) { string txt = await IPInfo.GetAsync((IPInfoKey)cmbFields.SelectedItem, GetValidIP(), txtToken.Text); MessageBox.Show(txt); SetControlsState(true); return; } result = await IPInfo.GetAsync(GetValidIP(), txtToken.Text); } else { if (cmbFields.SelectedIndex != 0) { MessageBox.Show(IPInfo.Get((IPInfoKey)cmbFields.SelectedItem, GetValidIP(), txtToken.Text)); SetControlsState(true); return; } result = IPInfo.Get(GetValidIP(), txtToken.Text); } PopulateTree(result); }
public static APIResult <sec_sessions> GetNewSession(sec_users usr, NameValueCollection request, int platform = 1) { using (var ctx = new MainEntities()) { IPResult s = new IPResult(); string ip = ""; string agent = ""; IPResult iploc = new IPResult(); try { ip = request.Get("REMOTE_ADDR"); agent = request.Get("HTTP_USER_AGENT"); iploc = General.GetResponse("http://ip-api.com/json/" + ip); } catch (Exception ex) { // return APIResult<sec_sessions>.Error(ResponseCode.BackendServerRequest, ex.Message + "get location ip:" + ip + " agent:" + agent); } try { var userSessions = ctx.sec_sessions.Where(a => a.user_id == usr.id && a.end_time == null && a.paltform == platform).FirstOrDefault(); if (userSessions != null) { return(APIResult <sec_sessions> .Success(userSessions, "User already logon!")); } Sessions ses = new Sessions(); ses.Entity.user_id = usr.id; ses.Entity.ip = request.Get("REMOTE_ADDR"); //IPResult iploc = new IPResult();// General.GetResponse("http://ip-api.com/json/" + ses.Entity.ip); ses.Entity.isp = iploc.isp; ses.Entity.lat = iploc.lat; ses.Entity.lon = iploc.lon; ses.Entity.timezone = iploc.timezone; ses.Entity.city = iploc.city; ses.Entity.country = iploc.country; ses.Entity.country_code = iploc.countryCode; ses.Entity.agent = request.Get("HTTP_USER_AGENT"); ses.Entity.paltform = platform; ses.Entity.browser = General.getAgent(ses.Entity.agent).name; ctx.sec_sessions.Add(ses.Entity); ctx.SaveChanges(); return(APIResult <sec_sessions> .Success(ses.Entity, "success")); } catch (Exception ex) { return(APIResult <sec_sessions> .Error(ResponseCode.BackendDatabase, ex.Message)); } } }
private static GeoLocation MapLocation(IPResult oIPResult) { 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() }); }
public override ICollection GetQueue() { var rawresult = cache.PurgeRawResult(); List <IPResult> queue = new List <IPResult>(); if (rawresult.Count > 0) { rawresult.GroupBy(s => s.ID).ToList().ForEach(s => { var res = s.ToList(); var ipres = new IPResult(s.Key, res[0].IP, res[0].ReportCount); ipres.AddResults(res); queue.Add(ipres); }); } return(queue); }
public IPResult PingAndGetIP(string ipRangeFrom, string ipRangeTo) { //Debug.WriteLine(Thread.CurrentThread.ManagedThreadId); Thread thread; List <IPInfo> iPInfos = new List <IPInfo>(); List <Thread> threads = new List <Thread>(); string IpRangeFromTemplate = ipRangeFrom.Substring(0, ipRangeFrom.LastIndexOf('.') + 1); int range = int.Parse(ipRangeFrom.Substring(ipRangeFrom.LastIndexOf('.') + 1)); string IpRangeFrom_ = IpRangeFromTemplate + range.ToString(); string IpRangeTo_ = ipRangeTo; IPResult results = new IPResult { ipRangeFrom = IpRangeFrom_, ipRangeTo = IpRangeTo_, Results = iPInfos }; while (results.ipRangeFrom.CompareTo(results.ipRangeTo) != 0) { thread = new Thread(ThreadFunction); threads.Add(thread); thread.Start(results); thread.Join(5); range++; results.ipRangeFrom = IpRangeFromTemplate + range.ToString(); } //foreach(var thread in threads) //{ // thread.Start(iPInfos); //} foreach (var x in threads) { try { if (x.IsAlive) { x.Join(); } } catch (Exception) { } } //Debug.WriteLine("Thread inside is alive !"); return(results); }
public ActionResult Index(string ip) { Regex regex = new Regex(Resource.Regexs["ip"]); IPDetails details = null; IPInfo ipInfo = null; if (regex.IsMatch(ip)) { ipInfo = IPInfoServices.LoadFirst(i => i.IP == ip); if (ipInfo == null) { ipInfo = IPResult.GetData(ip); //IPData ipData = IPResult.GetData(ip); //IPInfo ipInfoMapp = Mapper.Map<IPInfo>(ipData); ipInfo = IPInfoServices.AddEntity(ipInfo); } } details = Mapper.Map<IPDetails>(ipInfo); return View(details); }
public void Load(IPResult match) { ip = match.IP; if (match.TaskReports.Count > 0) { reports = new Models.ReportItem[match.TaskReports.Count]; for (int i = 0; i < reports.Length; i++) { reports[i] = new Models.ReportItem() { task = Enum.GetName(match.TaskReports[i].TaskType.GetType(), match.TaskReports[i].TaskType), start = match.TaskReports[i].Start, end = match.TaskReports[i].End, data = match.TaskReports[i].Data, state = Enum.GetName(match.TaskReports[i].State.GetType(), match.TaskReports[i].State), }; } } }
public async void ScanIp_Click(object sender, EventArgs e) { //Debug.WriteLine("Running !"); IPResult data = new IPResult(); string IpRangeFrom = ipFromBox.Text; string IpRangeTo = ipToBox.Text; ipScanner ipScanner = new ipScanner(); await Task.Run(async() => { //Debug.WriteLine("Thread : " + Thread.CurrentThread.ManagedThreadId + " is alive " + Thread.CurrentThread.IsAlive); data = ipScanner.PingAndGetIP(IpRangeFrom, IpRangeTo); int i = 0; foreach (var x in data.Results) { //Debug.WriteLine("Thread : " + Thread.CurrentThread.ManagedThreadId); i++; x.STT = i; } }); listIP.ItemsSource = data.Results; }
public static sec_sessions GetNewSession(sec_users usr, int platform = 1) { using (var ctx = new MainEntities()) { IPResult s = new IPResult(); string ip = ""; string agent = ""; IPResult iploc = new IPResult(); var request = HttpContext.Current.Request.ServerVariables; try { ip = request.Get("REMOTE_ADDR"); agent = request.Get("HTTP_USER_AGENT"); iploc = General.GetResponse("http://ip-api.com/json/" + ip); } catch (Exception ex) { // return APIResult<sec_sessions>.Error(ResponseCode.BackendServerRequest, ex.Message + "get location ip:" + ip + " agent:" + agent); } try { var userSessions = ctx.sec_sessions.Where(a => a.user_id == usr.id && a.end_time == null && a.paltform == platform && a.end_time == null).FirstOrDefault(); if (userSessions != null) { HttpContext.Current.Session.Clear(); HttpContext.Current.Session.Add("SESSION_ID", userSessions.id); return(userSessions); } sec_sessions ses = new sec_sessions(); ses.user_id = usr.id; ses.ip = request.Get("REMOTE_ADDR"); //IPiploc = new IPResult();// General.GetResponse("http://ip-api.com/json/" + ses.Entity.ip); ses.isp = iploc.isp; ses.lat = iploc.lat; ses.lon = iploc.lon; ses.timezone = iploc.timezone; ses.city = iploc.city; ses.country = iploc.country; ses.country_code = iploc.countryCode; ses.agent = request.Get("HTTP_USER_AGENT"); ses.paltform = platform; ses.browser = General.getAgent(ses.agent).name; ses.id = Guid.NewGuid(); ses.start_time = DateTime.Now; ctx.sec_sessions.Add(ses); ctx.SaveChanges(); HttpContext.Current.Session.Clear(); HttpContext.Current.Session.Add("SESSION_ID", ses.id); return(ses); } catch (Exception ex) { return(null); } } }
public async Task <APIResult <LoginResponse> > Auth(string email, string password, string first_name, string last_name, HttpContext http, string pic = "", string network = "", string FirebaseUID = "") { using (DAL.MainEntities ctx = new DAL.MainEntities()) { //try //{ tbl_accounts dbuser = null; try { if (email != "") { dbuser = ctx.tbl_accounts.Include("sec_users").Where(a => a.email == email).FirstOrDefault(); } else if (FirebaseUID != "") { dbuser = ctx.tbl_accounts.Include("sec_users").Where(a => a.sec_users.firebase_uid == FirebaseUID).FirstOrDefault(); } if (dbuser == null) { dbuser = new tbl_accounts(); dbuser.email = email; dbuser.first_name = first_name; dbuser.last_name = last_name; dbuser.register_time = DateTime.Now; ctx.tbl_accounts.Add(dbuser); try { ctx.SaveChanges(); sec_users sec_user = new sec_users(); sec_user.pwd = password; sec_user.id = dbuser.id; sec_user.mail_verified = true; if (FirebaseUID != "") { sec_user.firebase_uid = FirebaseUID; } ctx.sec_users.Add(sec_user); ctx.SaveChanges(); } //catch (DbEntityValidationException e) //{ // return new APIResult<LoginResponse>(ResultType.fail, null, General.fetchEntityError(e)); //} catch (Exception ex) { return(APIResult <LoginResponse> .Error(ResponseCode.BackendDatabase, ex.Message + "save changes1")); } } } catch (Exception ex) { return(APIResult <LoginResponse> .Error(ResponseCode.BackendDatabase, ex.Message + "get dbuser")); } tbl_images img = ctx.tbl_images.Where(a => a.model_name == "tbl_accounts" && a.model_id == dbuser.id && a.model_tag == "main").FirstOrDefault(); if (pic != "" && img == null) { img = new tbl_images(); try { img.original = "/Storage/Original/" + DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + network + ".jpg"; string imgPath = ConfigurationManager.AppSettings["mediaServer_Path"] + img.original.Replace("/", "\\"); img.large = img.original; img.thumb = img.original; img.meduim = img.original; img.model_id = dbuser.id; img.model_name = "tbl_accounts"; img.model_tag = "main"; System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Encoding = System.Text.Encoding.UTF8; webClient.DownloadFile(pic, imgPath); ctx.tbl_images.Add(img); } catch (Exception ex) { // return APIResult<LoginResponse>.(ResultType.fail, null, ex.Message + "Save Image"); } try { ctx.SaveChanges(); } //catch (DbEntityValidationException e) //{ // return new APIResult<LoginResponse>(ResultType.fail, null, General.fetchEntityError(e)); //} catch (Exception ex) { // return new APIResult<LoginResponse>(ResultType.fail, null, ex.Message + "save changes2"); } } var returned = new LoginResponse { account = dbuser }; IPResult s = new IPResult(); string ip = ""; string agent = ""; IPResult iploc = new IPResult(); //if(HttpContext.Current == null) return new APIResult<LoginResponse>(ResultType.fail, null, "Null HTTPContext"); //if (http.Request == null) return APIResult<LoginResponse>.Error(ResponseCode., null, "Null HTTPRequest"); //if (http.Request.ServerVariables == null) return new APIResult<LoginResponse>(ResultType.fail, null, "Null ServerVariables"); //if (http.Request.ServerVariables.Count == 0) return new APIResult<LoginResponse>(ResultType.fail, null, "Empty ServerVariables"); //if (!http.Request.ServerVariables.AllKeys.Contains("REMOTE_ADDR")) return new APIResult<LoginResponse>(ResultType.fail, null, "REMOTE_ADDR Not in ServerVariables"); //if (!http.Request.ServerVariables.AllKeys.Contains("HTTP_USER_AGENT")) return new APIResult<LoginResponse>(ResultType.fail, null, "HTTP_USER_AGENT No in ServerVariables"); try { ip = http.Request.ServerVariables.Get("REMOTE_ADDR"); agent = http.Request.ServerVariables.Get("HTTP_USER_AGENT"); iploc = General.GetResponse("http://ip-api.com/json/" + ip); } catch (Exception ex) { return(APIResult <LoginResponse> .Error(ResponseCode.BackendServerRequest, ex.Message + "get location ip:" + ip + " agent:" + agent)); } try { //&& a.ip == ip && a.agent == agent var userSessions = ctx.sec_sessions.Where(a => a.user_id == dbuser.id && a.end_time == null).FirstOrDefault(); if (userSessions == null) { Sessions ses = new Sessions(); ses.Entity.user_id = dbuser.id; ses.Entity.ip = ip; ses.Entity.isp = iploc.isp; ses.Entity.lat = iploc.lat; ses.Entity.lon = iploc.lon; ses.Entity.timezone = iploc.timezone; ses.Entity.city = iploc.city; ses.Entity.country = iploc.country; ses.Entity.country_code = iploc.countryCode; ses.Entity.agent = agent; ctx.sec_sessions.Add(ses.Entity); ctx.SaveChanges(); dbuser.sec_users.sec_sessions = new List <sec_sessions>() { ses.Entity }; returned.token = ses.Entity.id; } else { returned.token = userSessions.id; } returned.roles = ctx.sec_users_roles.Include("sec_roles").Where(a => a.user_id == dbuser.id).Select(b => b.sec_roles.role_key).ToArray(); return(APIResult <LoginResponse> .Success(returned, "Login Success")); } catch (DbEntityValidationException e) { return(APIResult <LoginResponse> .Error(ResponseCode.BackendDatabase, General.fetchEntityError(e))); } catch (Exception ex) { return(APIResult <LoginResponse> .Error(ResponseCode.BackendDatabase, ex.Message + " Save Session")); } //} //catch (Exception ex) //{ // throw new Exception( ex.Message + "Auth"); //} } }
public bool Parse(List <ILexToken> line, out IPResult result, int index = 0) { result = Parse(line, index, out var n, 0); return(n != -1); }
public SelectedResult(int index, IPResult result) { this.Index = index; this.Result = result; }