• Home
  • Linux
  • Docker
  • Windows
    • PS
    • C#
    • Exchange Server
  • Other
    • Perl
    • IPV6
    • MacOS
  • DB
    • MSSQL
    • MariaDB
    • PG

Home

чтение DNS лога

Details
Written by: po3dno
Category: C#
Created: 21 March 2019
Hits: 1271
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Text.RegularExpressions;
using System.Collections.Concurrent;
 
 
namespace dns_log_parser
{
    class Program
    {
 
        static long offset = 0;
        //static FileStream file;
        static StreamReader reader;
 
        static ConcurrentDictionary<(string, string), int> dnsstat = new ConcurrentDictionary<(string, string), int>();
        static void Main(string[] args)
        {
            if (args.Count() < 1) {
                Console.WriteLine("Usage: dns_log_parser.exe [path_to_log]");
                Environment.Exit(0);
            }
 
            string sourceFile = args[0];
 
            if (!File.Exists(sourceFile))
            {
                Console.WriteLine("{0} not exist", sourceFile);
                Environment.Exit(0);
            }
 
            offset = (new FileInfo(sourceFile)).Length;
 
            Timer t = new Timer(TimerCallback, null, 0, 2000);
 
            while (true)
            {
                FileStream file = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                var info = new FileInfo(sourceFile);
                if (info.Length < offset)
                    offset = 0;
                using (new StreamReader(file))
                {
                    file.Seek(offset, SeekOrigin.Begin);
                    reader = new StreamReader(file);
 
                    file.Seek(offset, SeekOrigin.Begin);
                    if (!reader.EndOfStream)
                    {
                        do
                        {
                            string line = reader.ReadLine();
                            // ^.+Rcv\s+([0-9\.]+)\s+([0-9A-Fa-f]+)\s+.+\[.+\]\s+(\w+)\s+\(\d\)(.+)\(0\)$
                            // https://answers.splunk.com/answers/132364/dns-debug-log-dns-log-format-review.html
                            Regex regex = new Regex(@"^.+Rcv\s+([0-9\.]+)\s+([0-9A-Fa-f]+)\s+.+\[.+\]\s+(\w+)\s+\(\d\)(.+)\(0\)$");
 
                            Match match = regex.Match(line);
                            if (match.Success)
                            {
                                string ip = match.Groups[1].Value;
                                //string dsthost = match.Groups[4].Value;
                                string dsthost = Regex.Replace(match.Groups[4].Value, @"\(\d+\)+", ".");
 
                                int curcount;
                                if (dnsstat.TryGetValue((ip, dsthost), out curcount))
                                {
                                    dnsstat[(ip, dsthost)] = curcount + 1;
                                    if (curcount % 10 == 0)
                                    {
                                        //Console.WriteLine("ip: {0} dns: {1} count: {2}", ip, dsthost, curcount);
                                    }
                                }
                                else
                                {
                                    dnsstat.TryAdd((ip, dsthost), 1);
                                }
 
                                //Console.WriteLine("{0} {1}", ip, dsthost);
                            }
                               
                        } while (!reader.EndOfStream);
 
                        offset = file.Position;
                        //Console.WriteLine("{0}", offset);
                    }
                    reader.Close();
                    Thread.Sleep(100);
                }
            }
        }
        private static void TimerCallback(Object o)
        {
            ConcurrentDictionary<(string, string), int> dnsstatviewtemp = dnsstat;
 
            var dnsstatview = dnsstatviewtemp.OrderByDescending(x => x.Value).Take(50);
 
            Console.Clear();
 
            foreach (KeyValuePair<(string, string), int> item in dnsstatview)
            {
                Console.WriteLine("Key: {0}, Value: {1}", item.Key, item.Value);
 
            }
 
        }
    }
}

mount vhd

Details
Written by: po3dno
Category: Power Shell
Created: 05 March 2019
Hits: 1142
Sysprep /generalize /shutdown /oobe

First, mount the vhd using

Mount-WindowsImage -ImagePath C:\VHDs\BigHomies.vhdx -Path C:\VHDMount -Index 1

Then, capture it into a wim with

New-WindowsImage -CapturePath C:\VHDMount -Name Win7Image -ImagePath C:\CapturedWIMs\Win7.wim -Description "Yet another Windows 7 Image" -Verify

And let it do it's thing. When you are done you can unmount the vhd and discard any changes using:

Dismount-WindowsImage -Path C:\VHDMount -Discard

SQL AG config multisubnets

Details
Written by: po3dno
Category: MSSQL
Created: 28 December 2018
Hits: 1227

sql01_sme_AG_sql01-sme1c         Online  sql01_sme_AG  Network Name

 

Get-ClusterResource sql01_sme_AG_sql01-sme1c |Set-ClusterParameter -Name RegisterAllProvidersIP -Value 0

Get-ClusterResource sql01_sme_AG_sql01-sme1c |Set-ClusterParameter -Name RegisterAllProvidersIP -Value 0

Get-ClusterResource sql01_sme_AG_sql01-sme1c  | Update-ClusterNetworkNameResource

Fix Recovery Pending State in SQL Server Database

Details
Written by: po3dno
Category: MSSQL
Created: 07 December 2018
Hits: 1256

ALTER DATABASE [DBName] SET EMERGENCY;

GO

ALTER DATABASE [DBName] set single_user

GO

DBCC CHECKDB ([DBName], REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS;

GO 

ALTER DATABASE [DBName] set multi_user

GO

Disable NETBIOS

Details
Written by: po3dno
Category: Power Shell
Created: 15 May 2018
Hits: 1229

Get-DhcpServerv4Scope -ComputerName SERVER | %{Set-DhcpServerv4OptionValue -ComputerName SERVER  -ScopeId $_.ScopeId -OptionId 1 -VendorClass "Параметры Microsoft" -Value "0x2" -Verbose}

  1. Files and Settings guide for Outlook
  2. InstallWinUpdates
  3. Exchange Server: Clear AutoDiscover Cache
  4. Calculate UAC

Subcategories

Power Shell Article Count:  53

C# Article Count:  10

Perl Article Count:  1

Exchange Server Article Count:  15

Other Article Count:  24

MSSQL Article Count:  17

Windows Article Count:  25

MariaDB Article Count:  3

Linux Article Count:  9

Docker Article Count:  3

pg Article Count:  2

Page 16 of 32

  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

Login Form

  • Forgot your password?
  • Forgot your username?

Statistics

  • Users 2
  • Articles 177
  • Articles View Hits 173554