HTTP 요청을 수신하고 해당 요청을 웹 서버에 전달하는 프로그램을 만들어야합니다.Jpcap을 사용하여 역방향 프록시 생성
Diagram http://img269.imageshack.us/img269/1862/h98trsly.jpg
내가 성공적으로 단지 자바 소켓을 사용하여이를 만든하지만 클라이언트가 Jpcap에서 구현 될 수있는 프로그램이 필요했습니다. 이것이 가능한지, 그리고이 프로젝트를 위해 읽어야 할 문학이 무엇인지 알고 싶습니다.
이것은 내가 함께 Jpcap 튜토리얼에서 조각을 바느질하여 지금 가지고있는 것입니다 :
import java.net.InetAddress;
import java.io.*;
import jpcap.*;
import jpcap.packet.*;
public class Router {
public static void main(String args[]) {
//Obtain the list of network interfaces
NetworkInterface[] devices = JpcapCaptor.getDeviceList();
//for each network interface
for (int i = 0; i < devices.length; i++) {
//print out its name and description
System.out.println(i+": "+devices[i].name + "(" + devices[i].description+")");
//print out its datalink name and description
System.out.println(" datalink: "+devices[i].datalink_name + "(" + devices[i].datalink_description+")");
//print out its MAC address
System.out.print(" MAC address:");
for (byte b : devices[i].mac_address)
System.out.print(Integer.toHexString(b&0xff) + ":");
System.out.println();
//print out its IP address, subnet mask and broadcast address
for (NetworkInterfaceAddress a : devices[i].addresses)
System.out.println(" address:"+a.address + " " + a.subnet + " "+ a.broadcast);
}
int index = 1; // set index of the interface that you want to open.
//Open an interface with openDevice(NetworkInterface intrface, int snaplen, boolean promics, int to_ms)
JpcapCaptor captor = null;
try {
captor = JpcapCaptor.openDevice(devices[index], 65535, false, 20);
captor.setFilter("port 80 and host 192.168.56.1", true);
} catch(java.io.IOException e) {
System.err.println(e);
}
//call processPacket() to let Jpcap call PacketPrinter.receivePacket() for every packet capture.
captor.loopPacket(-1,new PacketPrinter());
captor.close();
}
}
class PacketPrinter implements PacketReceiver {
//this method is called every time Jpcap captures a packet
public void receivePacket(Packet p) {
JpcapSender sender = null;
try {
NetworkInterface[] devices = JpcapCaptor.getDeviceList();
sender = JpcapSender.openDevice(devices[1]);
} catch(IOException e) {
System.err.println(e);
}
IPPacket packet = (IPPacket)p;
try {
// IP Address of machine sending HTTP requests (the client)
// It's still on the same LAN as the servers for testing purposes.
packet.dst_ip = InetAddress.getByName("192.168.56.2");
} catch(java.net.UnknownHostException e) {
System.err.println(e);
}
//create an Ethernet packet (frame)
EthernetPacket ether=new EthernetPacket();
//set frame type as IP
ether.frametype=EthernetPacket.ETHERTYPE_IP;
//set source and destination MAC addresses
// MAC Address of machine running reverse proxy server
ether.src_mac = new MacAddress("08:00:27:00:9C:80").getAddress();
// MAC Address of machine running web server
ether.dst_mac = new MacAddress("08:00:27:C7:D2:4C").getAddress();
//set the datalink frame of the packet as ether
packet.datalink=ether;
//send the packet
sender.sendPacket(packet);
sender.close();
//just print out a captured packet
System.out.println(packet);
}
}
어떤 도움을 크게 감상 할 수있다. 고맙습니다.
jpcap 제한을 가정하면서 실시간으로 wireshark 스타일의 http 추적을 수행하고 해당 패킷을 snarfing하고 적절한 위치에 요청한 다음 해당 응답을 응답 인 것처럼 클라이언트로 다시 리디렉션하는 방법에 대해 이야기하고 있습니까? 자체 요청에서? 패킷 캡처를 실제로 이해하지 못하거나 어려운 작업입니다. 시스코의 라우터에있는 Layer7 제품의 영역에서 이런 종류의 일이 아닌가? – ShabbyDoo
예, 올바른 ShabbyDoo입니다. –