简体   繁体   English

如何在mac上从java读取和写入原始ip包?

[英]How do I read and write raw ip packets from java on a mac?

What would be the easiest way to be able to send and receive raw network packets. 什么是能够发送和接收原始网络数据包的最简单方法。 Do I have to write my own JNI wrapping of some c API, and in that case what API am I looking for? 我是否必须编写自己的一些c API的JNI包装,在这种情况下,我在寻找什么API?

EDIT: I want to be able to do what wireshark does, ie record all incomming packets on an interface, and in addition be able to send back my own created packets. 编辑:我希望能够做Wirehark做的事情,即记录接口上的所有incomming数据包,此外还能够发回我自己创建的数据包。 And I want to do it on a mac. 我想在Mac上做到这一点。

如果你开始想要你需要数据包嗅探器这样的东西,你会想看看http://netresearch.ics.uci.edu/kfujii/jpcap/doc/

Raw Socket for Java is a request for JDK for a looong long time. Raw Socket for Java是一个长期以来对JDK的请求。 See the request here . 请在此处查看请求。 There's a long discussion there where you can look for workarounds and solutions. 在那里有一个长期的讨论,你可以在那里寻找解决方法和解决方案。 I once needed this for a simple PING operation, but I can't remember how I resolved this. 我曾经需要这个用于简单的PING操作,但我不记得我是如何解决这个问题的。 Sorry :) 抱歉:)

到目前为止,我最好的选择似乎是BPF api并编写一个精简的JNI包装器

You can't access raw sockets from pure Java, so you will need some sort of layer between your Java code and the network interfaces. 您无法从纯Java访问原始套接字,因此您需要在Java代码和网络接口之间使用某种层。

Also note that access to raw sockets is normally only available to "root" processes, since otherwise any user could both a) sniff all traffic, and b) generate spoofed packets. 另请注意,对原始套接字的访问通常仅适用于“根”进程,因为否则任何用户都可以a)嗅探所有流量,以及b)生成欺骗性数据包。

Rather than write your whole program so that it needs to run as "root", you might consider having the packet capture and generation done in a standalone program with some sort of IPC (RMI, named pipe, TCP socket, etc) to exchange the data with your Java app. 您可以考虑在一个独立程序中使用某种IPC(RMI,命名管道,TCP套接字等)来完成数据包捕获和生成,而不是编写整个程序以便它需要以“root”身份运行。您的Java应用程序的数据。

TINI is a java ethernet controller, which may have libraries and classes for directly accessing data from ethernet frames to TCP streams. TINI是一个java以太网控制器,它可能有用于直接访问从以太网帧到TCP流的数据的库和类。 You may be able to find something in there that implements your needed classes. 您可以在那里找到实现所需课程的内容。 If not, there should be pointers or user groups that will give you a head start. 如果没有,应该有指针或用户组,将为您提供一个良好的开端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Java中对UDP数据包进行IP欺骗/更改源地址/原始套接字编程? - How to do ip spoofing/change source address/raw socket programming for UDP packets in java? 在Java中,如何写入我最近读取的文件? - In Java, how do I write to a file I recently read from? 如何在BluetoothChat中从输入/输出流读取/写入原始十六进制字节? - How do I read/write raw hex bytes from input/output stream in BluetoothChat? 如何从Java中的外部进程读取和写入? - How do I read and write from an external process in Java? 如何从Java中的ArrayLists读取和写入文件 - How do I read and write a file from ArrayLists in Java 如何解析Java中来自套接字的TCP / IP数据包? - How to parse TCP/IP packets from socket in Java? 从Java中的IP地址捕获数据包详细信息 - Capture packets details from IP address in java 如何将从 WAV 文件读取的数据转换为 java 中的签名 16 位原始音频数据数组? - How do I convert data read from a WAV file to an array of signed 16-bit raw audio data in java? 如何通过Java从Internet读取TCP数据包的内容 - How to read contents of TCP packets from Internet by java 如何使用Java中的线程读写文件? - How do I read and write to a file using threads in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM