<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://mars.merhot.dk/w/index.php?action=history&amp;feed=atom&amp;title=6237_Programmering_II_%28Csharp%29_Agenda%2Fsolution_2</id>
		<title>6237 Programmering II (Csharp) Agenda/solution 2 - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://mars.merhot.dk/w/index.php?action=history&amp;feed=atom&amp;title=6237_Programmering_II_%28Csharp%29_Agenda%2Fsolution_2"/>
		<link rel="alternate" type="text/html" href="http://mars.merhot.dk/w/index.php?title=6237_Programmering_II_(Csharp)_Agenda/solution_2&amp;action=history"/>
		<updated>2026-05-05T15:58:34Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.29.0</generator>

	<entry>
		<id>http://mars.merhot.dk/w/index.php?title=6237_Programmering_II_(Csharp)_Agenda/solution_2&amp;diff=33474&amp;oldid=prev</id>
		<title>Micn at 07:13, 17 February 2016</title>
		<link rel="alternate" type="text/html" href="http://mars.merhot.dk/w/index.php?title=6237_Programmering_II_(Csharp)_Agenda/solution_2&amp;diff=33474&amp;oldid=prev"/>
				<updated>2016-02-17T07:13:28Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 07:13, 17 February 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;source lang=csharp&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;class Program&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;class Program&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; {&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l137&quot; &gt;Line 137:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 138:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; &amp;#160; &amp;#160; }&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; &amp;#160; &amp;#160; }&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; }&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; }&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/source&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Micn</name></author>	</entry>

	<entry>
		<id>http://mars.merhot.dk/w/index.php?title=6237_Programmering_II_(Csharp)_Agenda/solution_2&amp;diff=33473&amp;oldid=prev</id>
		<title>Micn: Created page with &quot;class Program     {         static StreamWriter outFile;         static StreamReader inFile;          static List&lt;Log&gt; packets = new List&lt;Log&gt;();          //     47 4.635842000  ...&quot;</title>
		<link rel="alternate" type="text/html" href="http://mars.merhot.dk/w/index.php?title=6237_Programmering_II_(Csharp)_Agenda/solution_2&amp;diff=33473&amp;oldid=prev"/>
				<updated>2016-02-17T07:12:50Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;class Program     {         static StreamWriter outFile;         static StreamReader inFile;          static List&amp;lt;Log&amp;gt; packets = new List&amp;lt;Log&amp;gt;();          //     47 4.635842000  ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;class Program&lt;br /&gt;
    {&lt;br /&gt;
        static StreamWriter outFile;&lt;br /&gt;
        static StreamReader inFile;&lt;br /&gt;
&lt;br /&gt;
        static List&amp;lt;Log&amp;gt; packets = new List&amp;lt;Log&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
        //     47 4.635842000    172.16.236.177        8.8.8.8               DNS      85     Standard query 0x2063  A lh4.googleusercontent.com&lt;br /&gt;
        static void analyze(List&amp;lt;String&amp;gt; lines)&lt;br /&gt;
        {&lt;br /&gt;
            if (lines.Count &amp;lt; 2) return;&lt;br /&gt;
&lt;br /&gt;
            //Protokol navnet står fra plads 69 og 9 pladser frem&lt;br /&gt;
            string protocol = lines[1].Substring(67, 9);&lt;br /&gt;
&lt;br /&gt;
            //Tilføj også kode der kan læse Source og Destination&lt;br /&gt;
            string source = lines[1].Substring(23, 22).Trim();&lt;br /&gt;
            string dest = lines[1].Substring(45, 22).Trim();&lt;br /&gt;
&lt;br /&gt;
            string info = lines[1].Substring(83).Trim();&lt;br /&gt;
&lt;br /&gt;
            if (protocol.Trim().ToUpper() == &amp;quot;ARP&amp;quot;)&lt;br /&gt;
            {&lt;br /&gt;
                &lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            if (protocol.Trim().ToUpper() == &amp;quot;DNS&amp;quot;)&lt;br /&gt;
            {&lt;br /&gt;
                //Tilføj kode her der tæller antallet af DNS og gemmer den URL der søges på&lt;br /&gt;
                if (info.Contains(&amp;quot;Standard query 0x&amp;quot;)) {&lt;br /&gt;
&lt;br /&gt;
                    string[] infoSplit = info.Split(' ');&lt;br /&gt;
                    packets.Add(new DnsQ(source, dest, protocol.Trim(), infoSplit[2], infoSplit[5]));&lt;br /&gt;
&lt;br /&gt;
                } else&lt;br /&gt;
                {&lt;br /&gt;
                    string[] infoSplit = info.Split(' ');&lt;br /&gt;
&lt;br /&gt;
                    var query = packets.Find(x =&amp;gt; {&lt;br /&gt;
&lt;br /&gt;
                        if (x.GetType() == typeof(DnsQ))&lt;br /&gt;
                            return ((DnsQ)x).Id == infoSplit[2];&lt;br /&gt;
                        else&lt;br /&gt;
                            return false;&lt;br /&gt;
                    });&lt;br /&gt;
&lt;br /&gt;
                    packets.Add(new DnsR(source, dest, protocol.Trim(), (DnsQ)query, info));&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static Dictionary&amp;lt;string, int&amp;gt; web = new Dictionary&amp;lt;string, int&amp;gt;();&lt;br /&gt;
        static void AddWebAddress(String address)&lt;br /&gt;
        {&lt;br /&gt;
            if (web.ContainsKey(address))&lt;br /&gt;
                web[address]++;&lt;br /&gt;
            else&lt;br /&gt;
                web[address] = 1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        //static void Main(string[] args)&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            inFile = new StreamReader(&amp;quot;logfile.txt&amp;quot;);&lt;br /&gt;
            outFile = new StreamWriter(&amp;quot;outLogs.txt&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
            String line;&lt;br /&gt;
            List&amp;lt;String&amp;gt; lines = new List&amp;lt;string&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
            while (!inFile.EndOfStream)&lt;br /&gt;
            {&lt;br /&gt;
                line = inFile.ReadLine();&lt;br /&gt;
                //Hvis line starter med No. er det en ny pakke, så skal vi først analysere den gamle&lt;br /&gt;
                if (line.StartsWith(&amp;quot;No.&amp;quot;) || inFile.EndOfStream)&lt;br /&gt;
                {&lt;br /&gt;
                    analyze(lines);&lt;br /&gt;
                    lines = new List&amp;lt;string&amp;gt;();&lt;br /&gt;
                }&lt;br /&gt;
                lines.Add(line);&lt;br /&gt;
            }&lt;br /&gt;
            inFile.Close();&lt;br /&gt;
            outFile.Close();&lt;br /&gt;
&lt;br /&gt;
            &lt;br /&gt;
&lt;br /&gt;
            Console.ReadLine();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public class Log&lt;br /&gt;
    {&lt;br /&gt;
        public string Source { get; set; }&lt;br /&gt;
        public string Destination { get; set; }&lt;br /&gt;
        public string Protocol { get; set; }&lt;br /&gt;
&lt;br /&gt;
        public Log(string source, string destination, string protocol)&lt;br /&gt;
        {&lt;br /&gt;
            Source = source;&lt;br /&gt;
            Destination = destination;&lt;br /&gt;
            Protocol = protocol;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public class DnsQ : Log&lt;br /&gt;
    {&lt;br /&gt;
        public string Id { get; set; }&lt;br /&gt;
        public string Url { get; set; }&lt;br /&gt;
&lt;br /&gt;
        public DnsQ(string source, string destination, string protocol, string id, string url):base(source, destination, protocol)&lt;br /&gt;
        {&lt;br /&gt;
            Id = id;&lt;br /&gt;
            Url = url;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public class DnsR : Log&lt;br /&gt;
    {&lt;br /&gt;
        public DnsQ Query { get; set; }&lt;br /&gt;
        private List&amp;lt;string&amp;gt; ipList = new List&amp;lt;string&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
        public DnsR(string source, string destination, string protocol, DnsQ query, string infoString):base(source, destination, protocol)&lt;br /&gt;
        {&lt;br /&gt;
            Query = query;&lt;br /&gt;
&lt;br /&gt;
            bool saveNext = false;&lt;br /&gt;
            foreach(string s in infoString.Split(' '))&lt;br /&gt;
            {&lt;br /&gt;
                if (s == &amp;quot;A&amp;quot;) saveNext = true;&lt;br /&gt;
                else saveNext = false;&lt;br /&gt;
&lt;br /&gt;
                if (saveNext)&lt;br /&gt;
                    ipList.Add(s);&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;/div&gt;</summary>
		<author><name>Micn</name></author>	</entry>

	</feed>