IP 패킷은 헤더와 페이로드로 구성됩니다. IPv4 패킷 헤더는 다음으로 구성됩니다.(2)
| 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | (비트 위치) |
| 실행 | 국제인도법 | QoS | 길이 | |||||||||||||||||||||||||||||
| 차별 | 0 | DF | MF | 조각 오프셋 | ||||||||||||||||||||||||||||
| TTL | 규약 | 체크섬 | ||||||||||||||||||||||||||||||
| 소스 IP | ||||||||||||||||||||||||||||||||
| 대상 IP | ||||||||||||||||||||||||||||||||
패키지(패키지, 문화적 언어: 마루, 패키지) 정보 기술~에 패키지 방법~에서 컴퓨터 네트워크중재 데이터제어 정보와 사용자 데이터로 구성된 A 패킷의 형식화된 블록입니다.(하나)그건 유효 탑재량패킷을 지원하지 않는 컴퓨터 통신 링크는 간단합니다. 바이트, 선, 때리다데이터를 독립적으로 순차적으로 전송합니다. 데이터가 패킷으로 포맷되면 네트워크는 긴 메시지를 보다 효율적이고 안정적으로 보낼 수 있습니다.
Wireshark가 심화됩니다.
Wireshark가 심화됩니다.
SharkFest 최초의 Wireshark 교육 컨퍼런스인 SharkFest에 대해 자세히 알아보십시오.
www.wireshark.org
비트(단위) – Wikipedia, the Freelance Encyclopedia
무료 백과사전 Wikipedia. 비트(이진수)(1)는 0 또는 1의 값을 가질 수 있으며 (2)는 각각 참, 거짓 또는 상호 배타적인 상태를 나타냅니다. 바이트는 비트의 모음입니다.
de.wikipedia.org
Wireshark가 심화됩니다.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using SharpPcap;
namespace _20200826_001
{
// 1. 설치 - 캡쳐 - 목록 - 선택 - 오픈 - 캡쳐
// 2. 캡쳐된 것을 요리하는 과정
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int Del_Button_Device(object sender)
{
int DeviceNum = Convert.ToInt32((sender as Button).Name.Substring("Facto".Length));
for (int iTemp = 0; iTemp < CaptureDeviceList.Instance.Count; iTemp++)
{
foreach (Control Temp in Controls) // controls라는 집합안에 버튼이 속해있음
{
if (Temp.Name == ("Facto" + iTemp))
{
Controls.Remove(Temp);
}
}
}
return DeviceNum;
}
private void Print_MAC(byte() EtherData)
{
Label aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Destination MAC";
aLabel.Name = "LabelDMAC";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 10);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Source MAC";
aLabel.Name = "LabelSMAC";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 40);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Next Protocal";
aLabel.Name = "LabelProto";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 70);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
string data = string.Format("{0:X2}", EtherData(0));
for (int iTemp = 1; iTemp < 6; ++iTemp)
{
data += string.Format("-{0:X2}", EtherData(iTemp));
}
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = data;
aLabel.Name = "LabelDMACData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 10);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
data = string.Format("{0:X2}", EtherData(6));
for (int iTemp = 7; iTemp < 12; ++iTemp)
{
data += string.Format("-{0:X2}", EtherData(iTemp));
}
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = data;
aLabel.Name = "LabelSMACData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 40);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
int iNum = BitConverter.ToInt16(EtherData.Skip<byte>(12).Take(2).Reverse<byte>().ToArray(), 0);
switch (iNum)
{
case 0x0800:
data = "IP";
break;
case 0x0200:
data = "Xerox PUP";
break;
case 0x0500:
data = "Sprite";
break;
case 0x0806:
data = "Address resolution";
break;
case 0x8035:
data = "Reverse ARP";
break;
case 0x809B:
data = "AppleTalk protocol";
break;
case 0x80F3:
data = "AppleTalk ARP";
break;
case 0x8100:
data = "IEEE 802.1Q VLAN tagging";
break;
case 0x8137:
data = "IPX";
break;
case 0x86dd:
data = "IP protocol version 6";
break;
case 0x9000:
data = "used to test interfaces";
break;
default:
data = "Unknown";
break;
}
aLabel.Text = data;
aLabel.Name = "LabelProtoData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 70);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
}
private void Print_IP(byte() IPData)
{
Label aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP Version";
aLabel.Name = "LabelIPV";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 100);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP Head Length";
aLabel.Name = "LabelIPHL";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 130);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP TOS";
aLabel.Name = "LabelIPTOS";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 160);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP Total Length";
aLabel.Name = "LabelIPTL";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 190);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP IDentification";
aLabel.Name = "LabelIPID";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 220);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Fragment DF";
aLabel.Name = "LabelFDF";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 250);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Fragment MF";
aLabel.Name = "LabelIFMF";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 270);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Fragment Offset";
aLabel.Name = "LabelIFOFF";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 290);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Time To Live";
aLabel.Name = "LabelIPTTL";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 290);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Time To Live";
aLabel.Name = "LabelPROTO";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 320);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
byte byteTemp = IPData(14);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = "IPv"+(byteTemp >> 4).ToString();
aLabel.Name = "LabelIPVData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 100);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = ((byteTemp & 0x0F) * 4).ToString()+" Bytes";
aLabel.Name = "LabelIPHLData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 130);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
byteTemp = IPData(15);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = String.Format("0X{0:X2}", byteTemp);
aLabel.Name = "LabelIPTOSData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 160);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
int iNum = BitConverter.ToInt16(IPData.Skip<byte>(16).Take(2).Reverse<byte>().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = iNum.ToString() + " Bytes";
aLabel.Name = "LabelIPTLData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 190);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
iNum = BitConverter.ToInt16(IPData.Skip<byte>(18).Take(2).Reverse().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = iNum.ToString();
aLabel.Name = "LabelIPIDData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 220);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
iNum = BitConverter.ToInt16(IPData.Skip<byte>(20).Take(2).Reverse().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = (0 != (iNum & (1 << 14))).ToString(); //0이 들어가 있으면 거짓이다.
aLabel.Name = "LabelFDFData"; //1BITE DONT FRAGMENT
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 250);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
iNum = BitConverter.ToInt16(IPData.Skip<byte>(20).Take(2).Reverse().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = (0 != (iNum & (1 << 13))).ToString(); //0이 들어가 있으면 거짓이다.
aLabel.Name = "LabelFMFData"; //1BITE MORE FRAGEMENT
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 270);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
iNum = BitConverter.ToInt16(IPData.Skip<byte>(20).Take(2).Reverse().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = (iNum & 0X1FFF).ToString();
aLabel.Name = "LabelFOFFSETData";// 13BITES
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 290);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
byteTemp = IPData(22);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = byteTemp.ToString();
aLabel.Name = "LabelTTLData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 290);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
byteTemp = IPData(22);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = "--------------";
aLabel.Name = "LabelPROTOData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 320);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
}
private void Facto_Click(object sender, EventArgs e)
{
int DeviceNum = Del_Button_Device(sender);
CaptureDeviceList.Instance(DeviceNum).Open(DeviceMode.Normal, 0);
RawCapture arawCapture = CaptureDeviceList.Instance(DeviceNum).GetNextPacket();// 패킷을 하나가져오는 과정
Print_MAC(arawCapture.Data); // 1계층 출력
Print_IP(arawCapture.Data);// 2계층 출력
}
private void button1_Click_1(object sender, EventArgs e)
{
List<string> NicName = new List<string>();
foreach (ICaptureDevice Temp in CaptureDeviceList.Instance)
{
string() arrTemp = Temp.ToString().Split('\n');
NicName.Add(arrTemp(1).Substring("FriendlyName: ".Length));
}
for (int iTemp = 0; iTemp < NicName.Count; iTemp++)
{
Button abutton = new Button();
abutton.Text = NicName(iTemp);
abutton.Name = "Facto" + iTemp;
abutton.Location = new Point(10, 10 + iTemp * 30);
abutton.Size = new Size(200, 22);
abutton.BackColor = Color.White;
abutton.Click += new EventHandler(Facto_Click);
Controls.Add(abutton);
}
(sender as Button).Enabled = false;
}
}
}
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using SharpPcap;
namespace _20200826_001
{
// 1. 설치 - 캡쳐 - 목록 - 선택 - 오픈 - 캡쳐
// 2. 캡쳐된 것을 요리하는 과정
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int Del_Button_Device(object sender)
{
int DeviceNum = Convert.ToInt32((sender as Button).Name.Substring("Facto".Length));
for (int iTemp = 0; iTemp < CaptureDeviceList.Instance.Count; iTemp++)
{
foreach (Control Temp in Controls) // controls라는 집합안에 버튼이 속해있음
{
if (Temp.Name == ("Facto" + iTemp))
{
Controls.Remove(Temp);
}
}
}
return DeviceNum;
}
private void Print_MAC(byte() EtherData)
{
Label aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Destination MAC";
aLabel.Name = "LabelDMAC";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 10);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Source MAC";
aLabel.Name = "LabelSMAC";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 40);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Next Protocal";
aLabel.Name = "LabelProto";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 70);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
string data = string.Format("{0:X2}", EtherData(0));
for (int iTemp = 1; iTemp < 6; ++iTemp)
{
data += string.Format("-{0:X2}", EtherData(iTemp));
}
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = data;
aLabel.Name = "LabelDMACData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 10);
Controls.Add(aLabel);
data = string.Format("{0:X2}", EtherData(6));
for (int iTemp = 7; iTemp < 12; ++iTemp)
{
data += string.Format("-{0:X2}", EtherData(iTemp));
}
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = data;
aLabel.Name = "LabelSMACData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 40);
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
int iNum = BitConverter.ToInt16(EtherData.Skip<byte>(12).Take(2).Reverse<byte>().ToArray(), 0);
switch (iNum)
{
case 0x0800:
data = "IP";
break;
case 0x0200:
data = "Xerox PUP";
break;
case 0x0500:
data = "Sprite";
break;
case 0x0806:
data = "Address resolution";
break;
case 0x8035:
data = "Reverse ARP";
break;
case 0x809B:
data = "AppleTalk protocol";
break;
case 0x80F3:
data = "AppleTalk ARP";
break;
case 0x8100:
data = "IEEE 802.1Q VLAN tagging";
break;
case 0x8137:
data = "IPX";
break;
case 0x86dd:
data = "IP protocol version 6";
break;
case 0x9000:
data = "used to test interfaces";
break;
default:
data = "Unknown";
break;
}
aLabel.Text = data;
aLabel.Name = "LabelProtoData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 70);
Controls.Add(aLabel);
}
private void Print_IP(byte() IPData)
{
Label aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP Version";
aLabel.Name = "LabelIPV";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 100);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP Head Length";
aLabel.Name = "LabelIPHL";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 130);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP TOS";
aLabel.Name = "LabelIPTOS";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 160);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP Total Length";
aLabel.Name = "LabelIPTL";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 190);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP IDentification";
aLabel.Name = "LabelIPID";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 220);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Fragment DF";
aLabel.Name = "LabelFDF";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 250);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Fragment MF";
aLabel.Name = "LabelIFMF";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 270);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Fragment Offset";
aLabel.Name = "LabelIFOFF";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 290);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
byte byteTemp = IPData(14);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = "IPv"+(byteTemp >> 4).ToString();
aLabel.Name = "LabelIPVData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 100);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = ((byteTemp & 0x0F) * 4).ToString()+" Bytes";
aLabel.Name = "LabelIPHLData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 130);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
byteTemp = IPData(15);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = String.Format("0X{0:X2}", byteTemp);
aLabel.Name = "LabelIPTOSData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 160);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
int iNum = BitConverter.ToInt16(IPData.Skip<byte>(16).Take(2).Reverse<byte>().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = iNum.ToString() + " Bytes";
aLabel.Name = "LabelIPTLData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 190);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
iNum = BitConverter.ToInt16(IPData.Skip<byte>(18).Take(2).Reverse().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = iNum.ToString();
aLabel.Name = "LabelIPIDData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 220);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
iNum = BitConverter.ToInt16(IPData.Skip<byte>(20).Take(2).Reverse().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = (0 != (iNum & (1 << 14))).ToString(); //0이 들어가 있으면 거짓이다.
aLabel.Name = "LabelFDFData"; //1BITE DONT FRAGMENT
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 250);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
iNum = BitConverter.ToInt16(IPData.Skip<byte>(20).Take(2).Reverse().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = (0 != (iNum & (1 << 13))).ToString(); //0이 들어가 있으면 거짓이다.
aLabel.Name = "LabelFMFData"; //1BITE MORE FRAGEMENT
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 270);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
iNum = BitConverter.ToInt16(IPData.Skip<byte>(20).Take(2).Reverse().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = (iNum & 0X1FFF).ToString();
aLabel.Name = "LabelFOFFSETData";// 13BITES
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 290);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
}
private void Facto_Click(object sender, EventArgs e)
{
int DeviceNum = Del_Button_Device(sender);
CaptureDeviceList.Instance(DeviceNum).Open(DeviceMode.Normal, 0);
RawCapture arawCapture = CaptureDeviceList.Instance(DeviceNum).GetNextPacket();// 패킷을 하나가져오는 과정
Print_MAC(arawCapture.Data); // 1계층 출력
Print_IP(arawCapture.Data);// 2계층 출력
}
private void button1_Click_1(object sender, EventArgs e)
{
List<string> NicName = new List<string>();
foreach (ICaptureDevice Temp in CaptureDeviceList.Instance)
{
string() arrTemp = Temp.ToString().Split('\n');
NicName.Add(arrTemp(1).Substring("FriendlyName: ".Length));
}
for (int iTemp = 0; iTemp < NicName.Count; iTemp++)
{
Button abutton = new Button();
abutton.Text = NicName(iTemp);
abutton.Name = "Facto" + iTemp;
abutton.Location = new Point(10, 10 + iTemp * 30);
abutton.Size = new Size(200, 22);
abutton.BackColor = Color.White;
abutton.Click += new EventHandler(Facto_Click);
Controls.Add(abutton);
}
(sender as Button).Enabled = false;
}
}
}

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using SharpPcap;
namespace _20200826_001
{
// 1. 설치 - 캡쳐 - 목록 - 선택 - 오픈 - 캡쳐
// 2. 캡쳐된 것을 요리하는 과정
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int Del_Button_Device(object sender)
{
int DeviceNum = Convert.ToInt32((sender as Button).Name.Substring("Facto".Length));
for (int iTemp = 0; iTemp < CaptureDeviceList.Instance.Count; iTemp++)
{
foreach (Control Temp in Controls) // controls라는 집합안에 버튼이 속해있음
{
if (Temp.Name == ("Facto" + iTemp))
{
Controls.Remove(Temp);
}
}
}
return DeviceNum;
}
private void Print_MAC(byte() EtherData)
{
Label aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Destination MAC";
aLabel.Name = "LabelDMAC";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 10);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Source MAC";
aLabel.Name = "LabelSMAC";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 40);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Next Protocal";
aLabel.Name = "LabelProto";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 70);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
string data = string.Format("{0:X2}", EtherData(0));
for (int iTemp = 1; iTemp < 6; ++iTemp)
{
data += string.Format("-{0:X2}", EtherData(iTemp));
}
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = data;
aLabel.Name = "LabelDMACData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 10);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
data = string.Format("{0:X2}", EtherData(6));
for (int iTemp = 7; iTemp < 12; ++iTemp)
{
data += string.Format("-{0:X2}", EtherData(iTemp));
}
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = data;
aLabel.Name = "LabelSMACData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 40);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
int iNum = BitConverter.ToInt16(EtherData.Skip<byte>(12).Take(2).Reverse<byte>().ToArray(), 0);
switch (iNum)
{
case 0x0800:
data = "IP";
break;
case 0x0200:
data = "Xerox PUP";
break;
case 0x0500:
data = "Sprite";
break;
case 0x0806:
data = "Address resolution";
break;
case 0x8035:
data = "Reverse ARP";
break;
case 0x809B:
data = "AppleTalk protocol";
break;
case 0x80F3:
data = "AppleTalk ARP";
break;
case 0x8100:
data = "IEEE 802.1Q VLAN tagging";
break;
case 0x8137:
data = "IPX";
break;
case 0x86dd:
data = "IP protocol version 6";
break;
case 0x9000:
data = "used to test interfaces";
break;
default:
data = "Unknown";
break;
}
aLabel.Text = data;
aLabel.Name = "LabelProtoData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 70);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
}
private void Print_IP(byte() IPData)
{
Label aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP Version";
aLabel.Name = "LabelIPV";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 100);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP Head Length";
aLabel.Name = "LabelIPHL";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 130);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP TOS";
aLabel.Name = "LabelIPTOS";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 160);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP Total Length";
aLabel.Name = "LabelIPTL";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 190);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "IP IDentification";
aLabel.Name = "LabelIPID";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 220);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Fragment DF";
aLabel.Name = "LabelFDF";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 250);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Fragment MF";
aLabel.Name = "LabelIFMF";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 270);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Fragment Offset";
aLabel.Name = "LabelIFOFF";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 290);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleCenter;
aLabel.Text = "Time To Live";
aLabel.Name = "LabelIPTTL";
aLabel.Size = new Size(120, 20);
aLabel.Location = new Point(240, 290);
aLabel.BorderStyle = BorderStyle.FixedSingle;
aLabel.BackColor = Color.LightGray;
Controls.Add(aLabel);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
byte byteTemp = IPData(14);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = "IPv"+(byteTemp >> 4).ToString();
aLabel.Name = "LabelIPVData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 100);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = ((byteTemp & 0x0F) * 4).ToString()+" Bytes";
aLabel.Name = "LabelIPHLData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 130);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
byteTemp = IPData(15);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = String.Format("0X{0:X2}", byteTemp);
aLabel.Name = "LabelIPTOSData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 160);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
int iNum = BitConverter.ToInt16(IPData.Skip<byte>(16).Take(2).Reverse<byte>().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = iNum.ToString() + " Bytes";
aLabel.Name = "LabelIPTLData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 190);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
iNum = BitConverter.ToInt16(IPData.Skip<byte>(18).Take(2).Reverse().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = iNum.ToString();
aLabel.Name = "LabelIPIDData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 220);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
iNum = BitConverter.ToInt16(IPData.Skip<byte>(20).Take(2).Reverse().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = (0 != (iNum & (1 << 14))).ToString(); //0이 들어가 있으면 거짓이다.
aLabel.Name = "LabelFDFData"; //1BITE DONT FRAGMENT
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 250);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
iNum = BitConverter.ToInt16(IPData.Skip<byte>(20).Take(2).Reverse().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = (0 != (iNum & (1 << 13))).ToString(); //0이 들어가 있으면 거짓이다.
aLabel.Name = "LabelFMFData"; //1BITE MORE FRAGEMENT
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 270);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
iNum = BitConverter.ToInt16(IPData.Skip<byte>(20).Take(2).Reverse().ToArray(), 0);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = (iNum & 0X1FFF).ToString();
aLabel.Name = "LabelFOFFSETData";// 13BITES
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 290);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
byteTemp = IPData(22);
aLabel = new Label();
aLabel.TextAlign = ContentAlignment.MiddleLeft;
aLabel.Text = byteTemp.ToString();
aLabel.Name = "LabelTTLData";
aLabel.Size = new Size(140, 20);
aLabel.Location = new Point(370, 290);
aLabel.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(aLabel);
}
private void Facto_Click(object sender, EventArgs e)
{
int DeviceNum = Del_Button_Device(sender);
CaptureDeviceList.Instance(DeviceNum).Open(DeviceMode.Normal, 0);
RawCapture arawCapture = CaptureDeviceList.Instance(DeviceNum).GetNextPacket();// 패킷을 하나가져오는 과정
Print_MAC(arawCapture.Data); // 1계층 출력
Print_IP(arawCapture.Data);// 2계층 출력
}
private void button1_Click_1(object sender, EventArgs e)
{
List<string> NicName = new List<string>();
foreach (ICaptureDevice Temp in CaptureDeviceList.Instance)
{
string() arrTemp = Temp.ToString().Split('\n');
NicName.Add(arrTemp(1).Substring("FriendlyName: ".Length));
}
for (int iTemp = 0; iTemp < NicName.Count; iTemp++)
{
Button abutton = new Button();
abutton.Text = NicName(iTemp);
abutton.Name = "Facto" + iTemp;
abutton.Location = new Point(10, 10 + iTemp * 30);
abutton.Size = new Size(200, 22);
abutton.BackColor = Color.White;
abutton.Click += new EventHandler(Facto_Click);
Controls.Add(abutton);
}
(sender as Button).Enabled = false;
}
}
}

