91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 343KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-06
  • 語言: Java
  • 標簽: ICMP??PING??java??

資源簡介

使用Java語言開發 基于ICMP協議 仿Windows系統的Ping程序 簡單實現 使用了Jpcap 計算機網絡課程設計的作業

資源截圖

代碼片段和文件信息

package?ping;

import?java.io.IOException;
import?java.net.Inet4Address;
import?java.net.InetAddress;
import?java.net.MalformedURLException;
import?java.net.URL;
import?java.net.UnknownHostException;
import?java.util.Scanner;

import?jpcap.JpcapCaptor;
import?jpcap.JpcapSender;
import?jpcap.NetworkInterface;
import?jpcap.NetworkInterfaceAddress;
import?jpcap.packet.EthernetPacket;
import?jpcap.packet.ICMPPacket;
import?jpcap.packet.IPPacket;
import?jpcap.packet.Packet;
import?util.Util;

public?class?Main?{

public?static?void?main(String[]?args)?{

NetworkInterface[]?devices?=?JpcapCaptor.getDeviceList();

InetAddress?ip?=?null;
String?strip?=?““;

if?(args.length?>?0)?{
strip?=?args[0];
}?else?{
System.out.print(“請輸入域名或者IP地址:“);
Scanner?sc?=?new?Scanner(System.in);
strip?=?sc.nextLine();
sc.close();
}

try?{
ip?=?InetAddress.getByName(strip);
}?catch?(UnknownHostException?e)?{
System.out.println(“無法找到主機:“?+?strip);
System.exit(0);
}

if?(args.length?>=?3?&&?args[1].toLowerCase().equals(“-n“))?{
try?{
int?times?=?Integer.parseInt(args[2]);
ping(devices[0]?ip?times);
}?catch?(NumberFormatException?e)?{
ping(devices[0]?ip?4);
}

}?else?{
ping(devices[0]?ip?4);
}

}

public?static?void?ping(NetworkInterface?device?InetAddress?dstIP?int?times)?{
InetAddress?srcIP?=?null;

for?(NetworkInterfaceAddress?addr?:?device.addresses)?{
if?(addr.address?instanceof?Inet4Address)?{
srcIP?=?addr.address;
break;
}
}


int?timeout?=?1000;
JpcapCaptor?captor?=?null;
try?{
captor?=?JpcapCaptor.openDevice(device?2000?false?timeout);
}?catch?(IOException?e)?{
e.printStackTrace();
}

byte[]?defaultGatewayMacAddress?=?null;
InetAddress?baiduIP?=?null;
try?{
baiduIP?=?InetAddress.getByName(“www.baidu.com“);
}?catch?(UnknownHostException?e1)?{
e1.printStackTrace();
}

while?(true)?{
try?{
new?URL(“http://www.baidu.com“).openStream().close();
}?catch?(MalformedURLException?e)?{
e.printStackTrace();
}?catch?(IOException?e)?{
e.printStackTrace();
}
Packet?p?=?captor.getPacket();

if?(p?==?null)?{
continue;
}

IPPacket?packet?=?(IPPacket)?p;

if?(packet?==?null)?{
System.out.println(“[調試信息]獲取默認網關MAC地址失敗,正在重試。。。“);
}?else?{
if?(packet.dst_ip.getHostAddress().equals(baiduIP.getHostAddress()))?{
defaultGatewayMacAddress?=?((EthernetPacket)?packet.datalink).dst_mac;
break;
}
}
}

System.out.println(“[調試信息]默認網關的MAC地址:“?+?Util.bytes2MacAddress(defaultGatewayMacAddress));
System.out.println();
System.out.println();

try?{
captor.setFilter(“icmp?and?src?host?“?+?dstIP.getHostAddress()?true);
}?catch?(IOException?e)?{
}

byte[]?data?=?“abcdefghijklmnopqrstuvwxyz123456“.getBytes();
JpcapSender?sender?=?captor.getJpcapSenderInstance();
short?seq?=?1;

System.out.println(String.format(“正在?Ping?%s?具有?%d?字節的數據:“?dstIP.getHostAddress()?data.length));

in

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-07-24?12:25??java_icmp_ping-master\
?????目錄???????????0??2018-07-24?12:25??java_icmp_ping-master\Jpcap\
?????目錄???????????0??2018-07-24?12:25??java_icmp_ping-master\Jpcap\Jpcap-0.7-32bit\
?????文件???????81920??2018-07-24?12:25??java_icmp_ping-master\Jpcap\Jpcap-0.7-32bit\Jpcap.dll
?????文件???????27288??2018-07-24?12:25??java_icmp_ping-master\Jpcap\Jpcap-0.7-32bit\jpcap.jar
?????目錄???????????0??2018-07-24?12:25??java_icmp_ping-master\Jpcap\Jpcap-64bit\
?????文件???????89600??2018-07-24?12:25??java_icmp_ping-master\Jpcap\Jpcap-64bit\Jpcap.dll
?????文件???????18192??2018-07-24?12:25??java_icmp_ping-master\Jpcap\Jpcap-64bit\jpcap.jar
?????文件?????????400??2018-07-24?12:25??java_icmp_ping-master\README.md
?????目錄???????????0??2018-07-24?12:25??java_icmp_ping-master\libs\
?????文件???????18192??2018-07-24?12:25??java_icmp_ping-master\libs\jpcap.jar
?????文件??????214790??2018-07-24?12:25??java_icmp_ping-master\screenshot.jpg
?????目錄???????????0??2018-07-24?12:25??java_icmp_ping-master\src\
?????目錄???????????0??2018-07-24?12:25??java_icmp_ping-master\src\ping\
?????文件????????5425??2018-07-24?12:25??java_icmp_ping-master\src\ping\Main.java
?????文件????????5762??2018-07-24?12:25??java_icmp_ping-master\src\ping\Main2.java
?????目錄???????????0??2018-07-24?12:25??java_icmp_ping-master\src\util\
?????文件????????1333??2018-07-24?12:25??java_icmp_ping-master\src\util\Util.java
?????文件????????1687??2018-07-24?12:25??java_icmp_ping-master\src\util\Util2.java

評論

共有 條評論