1
我想在WiFi網絡中發送和接收數據包。 使用以下代碼在WiFi網絡中無法使用jpcap接收數據包
發送數據包。
int id = Integer.parseInt(text_device.getText().trim());
JpcapCaptor jpcap = JpcapCaptor.openDevice(devices[id], 65535, true, 20);
JpcapSender sender = jpcap.getJpcapSenderInstance();
TCPPacket packet = new TCPPacket(210, 210, 0l, 12l, true, true, true, true, true, true, true, true, 1, 2);
packet.setIPv4Parameter(0, true, true, true, 0, true, true, true, 0, 1010101, 100, IPPacket.IPPROTO_TCP, InetAddress.getLocalHost(), InetAddress.getByName(text_ip.getText().trim()));
packet.data = "Sample Data".getBytes();
Date date = new Date();
packet.usec = date.getTime();
packet.sec = date.getTime();
EthernetPacket ether = new EthernetPacket();
ether.src_mac = new byte[]{(byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1};
ether.dst_mac = new byte[]{(byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255};
ether.frametype = EthernetPacket.ETHERTYPE_IP;
packet.datalink = ether;
sender.sendPacket(packet);
要接收數據包,我寫這篇文章的代碼public void receivePacket(Packet packet)
TCPPacket tcp = (TCPPacket) packet;
String src = tcp.src_ip.getHostAddress();
int src_port = tcp.src_port;
String dst = tcp.dst_ip.getHostAddress();
int dst_port = tcp.dst_port;
String data = new String(tcp.data);
System.out.println("" + data + "");
當我兩臺機器連接局域網它的工作原理,但不能當我與無線網絡連接到接收數據包。
任何人都可以建議我,怎麼回事?
你建議我現在應該做什麼..因爲我必須使用Windows? – ELITE