یک برنامه نویس مبتدی

یادداشت های بک برنامه نویس

یک برنامه نویس مبتدی

یادداشت های بک برنامه نویس

آشنایی با کتابخانه قدرتمند PCap.Net - بخش دوم

دریافت اطلاعات پیشرفته درباره کارت های شبکه نصب شده

درس قبلی (دریافت لیست کارتهای شبکه) ، نشان دهنده نحوه دریافت اطلاعات پایه ای (شامل نام و توضیحات) درباره کارت های شبکه موجود بود. Pcap.Net  همچنین اطلاعات پیشرفته دیگری را نیز تدارک می بیند.

عموماً هرنمونه از LivePacketDevice که توسط LivePacket.AllLocalMacin برگشت داده می شود شامل لیستی از نمونه های DeviceAddress شامل موارد زیر است:

§         آدرس واسط شبکه

§         ماسک شبکه

§         آدرس پخش همگانی

§         آدرس مقصد

مثال بعدی ، تابع DevicePrint() را تدارک دیده است که تمام اطلاعات یک نمونه از LivePacketDevice را چاپ می کند. این تابع ، برای هرگزینه برگشتی از LivePacket.AllLocalMacine  توسط برنامه فراخوانی می شود.

 

using System;

using System.Collections.Generic;

using System.Linq;

using PcapDotNet.Core;

 

namespace ObtainingAdvancedInformationAboutInstalledDevices

{

    class Program

    {

        static void Main(string[] args)

        {

            // Retrieve the interfaces list

            IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;

 

            // Scan the list printing every entry

            for (int i = 0; i != allDevices.Count(); ++i)

                DevicePrint(allDevices[i]);

        }

 

 

 

 

 

        // Print all the available information on the given interface

        private static void DevicePrint(IPacketDevice device)

        {

            // Name

            Console.WriteLine(device.Name);

 

            // Description

            if (device.Description != null)

                Console.WriteLine("\tDescription: " + device.Description);

 

            // Loopback Address

            Console.WriteLine("\tLoopback: " +

                              (((device.Attributes & DeviceAttributes.Loopback) == DeviceAttributes.Loopback)

                                   ? "yes"

                                   : "no"));

 

            // IP addresses

            foreach (DeviceAddress address in device.Addresses)

            {

                Console.WriteLine("\tAddress Family: " + address.Address.Family);

 

                if (address.Address != null)

                    Console.WriteLine(("\tAddress: " + address.Address));

                if (address.Netmask != null)

                    Console.WriteLine(("\tNetmask: " + address.Netmask));

                if (address.Broadcast != null)

                    Console.WriteLine(("\tBroadcast Address: " + address.Broadcast));

                if (address.Destination != null)

                    Console.WriteLine(("\tDestination Address: " + address.Destination));

            }

            Console.WriteLine();

        }

    }

} 

نظرات 0 + ارسال نظر
برای نمایش آواتار خود در این وبلاگ در سایت Gravatar.com ثبت نام کنید. (راهنما)
ایمیل شما بعد از ثبت نمایش داده نخواهد شد