private void FillGrid()
{
Process netsend = new Process();
netsend.StartInfo.FileName = "net.exe";
netsend.StartInfo.CreateNoWindow = true;
netsend.StartInfo.Arguments = "view";
netsend.StartInfo.RedirectStandardOutput = true;
netsend.StartInfo.UseShellExecute = false;
netsend.StartInfo.RedirectStandardError = true;
netsend.Start();
StreamReader sr = new StreamReader(netsend.StandardOutput.BaseStream, netsend.StandardOutput.CurrentEncoding);
DataTable myDataTable = new DataTable();
DataColumn myDataColumn;
DataRow myDataRow;
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "ServerName";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "IpAddress";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "MacAddress";
myDataTable.Columns.Add(myDataColumn);
ArrayList Name = new ArrayList();
ArrayList IpAddress = new ArrayList();
int i = 0;
string sss = "";
try
{
while ((sss = sr.ReadLine()) != null)
{
if (sss.StartsWith("\\"))
{
myDataRow = myDataTable.NewRow();
Name.Add(sss.Substring(2).Substring(0, sss.Substring(2).IndexOf(" ")).ToUpper());
if (Name[i].ToString() != "PS1")
{
myDataRow["ServerName"] = Name[i].ToString();
IPHostEntry myIP = System.Net.Dns.GetHostByName(Name[i].ToString());
IPAddress[] addr = myIP.AddressList;
myDataRow["IpAddress"] = addr[0].ToString();
myDataRow["MacAddress"] = GetMacAddress(addr[0].ToString());
myDataTable.Rows.Add(myDataRow);
i++;
}
}
}
dataGrid1.DataSource = myDataTable;
}
catch { }
}
No comments:
Post a Comment