<commit_before>﻿using System;
using System.Management;
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
using System.Collections.Generic;
using System.Text;

namespace Andromeda
{
    public class NetworkConnections
    {
        private Ping ping;
        private PingOptions pingOptions;

        // Constructor
        public NetworkConnections()
        {
            ping = new Ping();
            
            pingOptions = new PingOptions();
            pingOptions.DontFragment = true;
            
        }

        // Ping test for single machine.
        public string PingTest(string hostname)
        {
            string returnMsg = "";
            if (hostname == "" || hostname == null)
            {
                return "No host was specified, please check the device list and try again.";
            }
            
            try 
            {
                PingReply pr = ping.Send(hostname);
                // If the ping reply isn't null...
                if (pr != null)
                {
                    // based on our connection status, return a message
                    switch (pr.Status)
                    {
                        case IPStatus.Success:
                            returnMsg = string.Format("Reply from {0} with address {1}", hostname, pr.Address);
                            break;
                        case IPStatus.TimedOut:
                            returnMsg = "Connection has timed out.";
                            break;
                        default:
                            returnMsg = string.Format("Ping to {0} failed: {1}", hostname, pr.Status.ToString());
                            break;
                    }
                }
                else
                {
                    // if it isn't null, but fails anyway, I'm not exactly certain why we would have an error.
                    returnMsg = "Connection failed for an unknown reason.";
                }
            }
            catch (PingException ex)
            {
                returnMsg = string.Format("Connection Error: {0}", ex.Message);
            }
            catch (SocketException ex)
            {
                returnMsg = string.Format("Connection Error: {0}", ex.Message);
            }

            return returnMsg;
        }

        // Return dictionary of results based on list of computers from a List<string> of hostnames.
        public Dictionary<string, string> PingTestDictionaryResult(List<string> hostnames)
        {
            Dictionary<string,string> returnMsgs = new Dictionary<string,string>(); ;
            foreach (string host in hostnames)
            {
                returnMsgs.Add(host, PingTest(host));
            }

            return returnMsgs;
        }

        public ManagementScope ConnectToRemoteWMI(string hostname)
        {
            ManagementScope wmiscope = new ManagementScope("\\\\"+hostname+"\\root\\cimv2");
            wmiscope.Connect();
            ResultConsole.AddConsoleLine("Connected to WMI scope " + wmiscope.Path);
            return wmiscope;
        }
    }
}<commit_msg>implemented a check for whether WMI is accessible or not on a given host<commit_after>﻿using System;
using System.Management;
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
using System.Collections.Generic;
using System.Text;

namespace Andromeda
{
    public class NetworkConnections
    {
        private Ping ping;
        private PingOptions pingOptions;

        // Constructor
        public NetworkConnections()
        {
            ping = new Ping();
            
            pingOptions = new PingOptions();
            pingOptions.DontFragment = true;
            
        }

        // Ping test for single machine.
        public string PingTest(string hostname)
        {
            string returnMsg = "";
            if (hostname == "" || hostname == null)
            {
                return "No host was specified, please check the device list and try again.";
            }
            
            try 
            {
                PingReply pr = ping.Send(hostname);
                // If the ping reply isn't null...
                if (pr != null)
                {
                    // based on our connection status, return a message
                    switch (pr.Status)
                    {
                        case IPStatus.Success:
                            returnMsg = string.Format("Reply from {0} with address {1}", hostname, pr.Address);
                            break;
                        case IPStatus.TimedOut:
                            returnMsg = "Connection has timed out.";
                            break;
                        default:
                            returnMsg = string.Format("Ping to {0} failed: {1}", hostname, pr.Status.ToString());
                            break;
                    }
                }
                else
                {
                    // if it isn't null, but fails anyway, I'm not exactly certain why we would have an error.
                    returnMsg = "Connection failed for an unknown reason.";
                }
            }
            catch (PingException ex)
            {
                returnMsg = string.Format("Connection Error: {0}", ex.Message);
            }
            catch (SocketException ex)
            {
                returnMsg = string.Format("Connection Error: {0}", ex.Message);
            }

            return returnMsg;
        }

        // Return dictionary of results based on list of computers from a List<string> of hostnames.
        public Dictionary<string, string> PingTestDictionaryResult(List<string> hostnames)
        {
            Dictionary<string,string> returnMsgs = new Dictionary<string,string>(); ;
            foreach (string host in hostnames)
            {
                returnMsgs.Add(host, PingTest(host));
            }

            return returnMsgs;
        }

        public ManagementScope ConnectToRemoteWMI(string hostname, string scope)
        {
            ManagementScope wmiscope = new ManagementScope("\\\\" + hostname + scope);
            wmiscope.Connect();
            return wmiscope;
        }

        public bool CheckWMIAccessible(string hostname, string scope)
        {
            ManagementScope wmiscope = ConnectToRemoteWMI(hostname, scope);
            if (wmiscope.IsConnected) { ResultConsole.AddConsoleLine("Connected to WMI scope " + wmiscope.Path); }
            else { ResultConsole.AddConsoleLine("Connection to WMI scope " + wmiscope.Path + " failed."); }
            return wmiscope.IsConnected;
        }


    }
}
{'fraction_non_alphanumeric': 0.08185741925881827, 'fraction_numerical': 0.0019348117279357048, 'mean_word_length': 1.33983286908078, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3004151', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1533, 'n_words': 454}