using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Threading;
using System.Web;
using System.Windows;
using System.Data;
using System.Drawing;
using System.Collections;
using System.Data.SqlClient;
using System.Net;
using System.Net.NetworkInformation;
namespace CheckChipInformation.V1._00
{
class Program
{
public static List<String> GetAllChipInformaton;
public static List<String> GetAllChipInformaton_Values;
public static String GetChipInformation=String.Empty;
static int Main(string[] args)
{
if (args.Length == 2)
{
GetAllChipInfo();
if (args[0] == @"/C")
{
GetChipInformation = args[1];
if (CompareString(GetChipInformation))
{
if (CreateLogFile(GetChipInformation, "MB.DAT"))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Check Network Interfaces Information Succeed.");
Console.ResetColor();
return 0;
}
else
return 1;
}
else
return 1;
}
else if (args[0] == @"/R")
{
if (CreateNetWorkLog(args[1]))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Read All NetWork Interfaces Information Succeed.");
Console.ResetColor();
return 0;
}
else
return 1;
}
else
{
help();
return 1;
}
}
help();
return 1;
}
public static Boolean CreateLogFile(String Str, String FileName)//生成LOG文件
{
Boolean Flag = false;
FileStream fs = new FileStream(FileName,FileMode.Create,FileAccess.Write);
try
{
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(Str);
sw.Close();
Flag = true;
}
catch (Exception ex)
{
Flag = false;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.ToString());
Console.WriteLine("Not Create " + FileName + " Log File!!");
Console.ResetColor();
return Flag;
}
finally
{
fs.Close();
}
return Flag;
}
public static Boolean CreateNetWorkLog(String FileName)//读取所有网口信息并存档
{
Boolean Flag = false;
FileStream fs = new FileStream(FileName, FileMode.Create, FileAccess.Write);
try
{
StreamWriter sw = new StreamWriter(fs);
foreach (String ss in GetAllChipInformaton)
sw.WriteLine(ss);
sw.Close();
Flag = true;
}
catch (Exception ex)
{
Flag = false;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.ToString());
Console.WriteLine("Not Create "+FileName+" Log File!!");
Console.ResetColor();
return Flag;
}
finally
{
fs.Close();
}
return Flag;
}
public static void help()//帮助信息
{
Title();
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine(@"/C Check Network Interfaces Information.");
Console.WriteLine(@"/R Read All Network Interfaces Information.");
Console.WriteLine(@"Example_1:*.exe /C 'Realtek PCIe GBE Family'");
Console.WriteLine(@"Example_2:*.exe /R NetWorkCardInformaton.log");
Console.ResetColor();
}
public static void Title()//标头信息
{
Console.Clear();//清屏
Console.WriteLine("Program Version V1.00 Create Date:2019-04-10");
Console.WriteLine("Property in Copyright Feres ShenBo.");
Console.WriteLine("-----------------------------------------------------------");
}
public static Boolean CompareString(String Str)//比较字符串
{
Boolean Flag = false;
foreach (String rd in GetAllChipInformaton_Values)
{
if (rd.ToUpper().Contains(Str.ToUpper()))
{
Flag = true;
/*Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Check Network Interfaces Information Succeed.");
Console.ResetColor();*/
return Flag;
}
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Check Network Interfaces Information Fail.");
Console.ResetColor();
return Flag;
}
public static Boolean GetAllChipInfo()
{
Boolean Flag = false;
try
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
GetAllChipInformaton = new List<String>();
GetAllChipInformaton_Values = new List<String>();
int index = 0;
foreach (NetworkInterface adapter in adapters)
{
index++;
GetAllChipInformaton.Add(adapter.Name + "=" + adapter.Description);
GetAllChipInformaton_Values.Add(adapter.Description);
}
Flag = true;
}
catch (Exception ex)
{
Flag = false;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.ToString());
Console.WriteLine("Read NetWork Card InterFace Information Err!!");
Console.ResetColor();
}
return Flag;
}
}
}