从输入的IP中获取子网范围以读取Excel电子表格

时间:2017-03-23 16:17:43

标签: c# excel ip console-application subnet

我有一个程序,我在其中输入IP获取主机名。我有一个导入有数千个子网范围的Excel工作表,我试图用它们做的是在输入IP时通过电子表格查找,得到最接近的匹配并打印出整个行和列的电子表格到控制台。我有一个打印出第一行的测试代码,但那就是它。

因此,在程序结束时,它会打印,ip,主机以及该行中的所有内容。除了能够搜索范围之外,我拥有一切。

using System;
using System.Net;
using Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;
using System.Data.OleDb;
using System.Data;
using System.Runtime.InteropServices;

namespace Investigations
{
    class Program
    {





        static void Main(string[] args)
        {
            int rCnt = 0;
            int cCnt = 0;
            string str;


            IPAddress addr = IPAddress.Parse("8.8.8.8");
            IPHostEntry entry = Dns.GetHostEntry(addr);
            Console.WriteLine("IP Address: " + addr);
            Console.WriteLine("Host Name: " + entry.HostName);


            Excel.Application xlApp = new Excel.Application();
            Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\ipsheet.xlxs");
            Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
            Excel.Range xlRange = xlWorksheet.UsedRange;
            Excel.Range currentFind = null;
            Excel.Range firstFind = null;
            Excel.XlFindLookIn xlValues;
            Excel.XlLookAt xlPart;

0 个答案:

没有答案