本文整理汇总了Java中org.pcap4j.packet.namednumber.TcpPort类的典型用法代码示例。如果您正苦于以下问题:Java TcpPort类的具体用法?Java TcpPort怎么用?Java TcpPort使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TcpPort类属于org.pcap4j.packet.namednumber包,在下文中一共展示了TcpPort类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TrexTcpPacket
import org.pcap4j.packet.namednumber.TcpPort; //导入依赖的package包/类
/**
*
*/
public TrexTcpPacket() {
this.dataOffset = 5;
this.reserved = (byte) 11;
this.ack = false;
this.urg = false;
this.fin = false;
this.psh = false;
this.rst = false;
this.syn = false;
this.window = (short) 9999;
this.checksum = (short) 0xABCD;
this.urgentPointer = (short) 1111;
this.srcPort = TcpPort.getInstance((short) 0);
this.dstPort = TcpPort.getInstance((short) 0);
this.sequenceNumber = 1234567;
this.acknowledgmentNumber = 7654321;
}
示例2: testHandleDnsRequestNotUdpPacket
import org.pcap4j.packet.namednumber.TcpPort; //导入依赖的package包/类
@Test
public void testHandleDnsRequestNotUdpPacket() throws Exception {
TcpPacket.Builder payLoadBuilder = new TcpPacket.Builder()
.srcPort(TcpPort.HTTP)
.dstPort(TcpPort.HTTP)
.srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(new byte[0])
);
IpPacket ipOutPacket = new IpV4Packet.Builder()
.version(IpVersion.IPV4)
.tos(IpV4Rfc791Tos.newInstance((byte) 0))
.protocol(IpNumber.UDP)
.srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNull(mockEventLoop.lastOutgoing);
assertNull(mockEventLoop.lastResponse);
}
示例3: createSyncAck
import org.pcap4j.packet.namednumber.TcpPort; //导入依赖的package包/类
static Packet createSyncAck(
MacAddress srcAddress_mac,
MacAddress dstAddrress_mac,
Inet4Address srcAddress,short srcPort,
Inet4Address dstAddress,short dstPort,
int ack_sequence,int sequence,short ident){
TcpPacket.Builder builder_tcp=new TcpPacket.Builder();
//builder_tcp.payloadBuilder(new UnknownPacket.Builder().rawData(new byte[0]));
builder_tcp.correctChecksumAtBuild(true);
builder_tcp.correctLengthAtBuild(true);
builder_tcp.paddingAtBuild(true);
builder_tcp.ack(true);
builder_tcp.acknowledgmentNumber(ack_sequence);
//builder_tcp.checksum(tcpHeader.getChecksum());
//builder_tcp.dataOffset((byte) 8);
builder_tcp.dstAddr(dstAddress);
builder_tcp.dstPort(new TcpPort(dstPort,""));
//builder_tcp.fin(tcpHeader.getFin());
ArrayList<TcpOption> tcp_options=new ArrayList<TcpOption>();
TcpNoOperationOption nop=TcpNoOperationOption.getInstance();
TcpMaximumSegmentSizeOption seg_option=new TcpMaximumSegmentSizeOption.Builder().maxSegSize(mtu).correctLengthAtBuild(true).build();
tcp_options.add(seg_option);
tcp_options.add(nop);
tcp_options.add(nop);
TcpSackPermittedOption sack_permit_option=TcpSackPermittedOption.getInstance();
tcp_options.add(sack_permit_option);
tcp_options.add(nop);
TcpWindowScaleOption win_option=new TcpWindowScaleOption.Builder().shiftCount(shiftCount).correctLengthAtBuild(true).build();
tcp_options.add(win_option);
builder_tcp.options(tcp_options);
//builder_tcp.padding(tcpHeader.getPadding());
builder_tcp.psh(false);
builder_tcp.reserved((byte) 0);
builder_tcp.rst(false);
builder_tcp.sequenceNumber(sequence);
builder_tcp.srcAddr(srcAddress);
builder_tcp.srcPort(new TcpPort(srcPort,""));
builder_tcp.syn(true);
builder_tcp.urg(false);
//builder_tcp.urgentPointer(tcpHeader.getUrgentPointer());
builder_tcp.window( window);
IpV4Packet.Builder builder_ipv4=new IpV4Packet.Builder();
builder_ipv4.correctChecksumAtBuild(true);
builder_ipv4.correctLengthAtBuild(true);
builder_ipv4.paddingAtBuild(true);
builder_ipv4.dstAddr(dstAddress);
builder_ipv4.dontFragmentFlag(true);
builder_ipv4.fragmentOffset((short)0);
//builder_ipv4.headerChecksum(ipV4Header.getHeaderChecksum());
// short identification= Math.abs(random.nextInt(Short.MAX_VALUE));
builder_ipv4.identification(ident);
builder_ipv4.ihl((byte) 5);
//builder_ipv4.moreFragmentFlag(ipV4Header.getMoreFragmentFlag());
//builder_ipv4.options(ipV4Header.getOptions());
//builder_ipv4.padding(ipV4Header.getPadding());
builder_ipv4.protocol(IpNumber.TCP);
// builder_ipv4.reservedFlag(ipV4Header.getReservedFlag());
builder_ipv4.srcAddr(srcAddress);
builder_ipv4.tos(IpV4Rfc1349Tos.newInstance((byte) 0));
//builder_ipv4.totalLength( 52);
builder_ipv4.ttl(ttl);
builder_ipv4.version(IpVersion.IPV4);
builder_ipv4.payloadBuilder(builder_tcp);
//
Packet p = buildIpV4(srcAddress_mac,dstAddrress_mac,builder_ipv4);
return p;
}
示例4: createDataPacket
import org.pcap4j.packet.namednumber.TcpPort; //导入依赖的package包/类
static Packet createDataPacket(
MacAddress srcAddress_mac,
MacAddress dstAddrress_mac,
Inet4Address srcAddress,short srcPort,
Inet4Address dstAddress,short dstPort,
int sequence,int ack, byte[] data,short ident){
Packet p=null;
TcpPacket.Builder builder_tcp=new TcpPacket.Builder();
builder_tcp.payloadBuilder(new UnknownPacket.Builder().rawData(data));
builder_tcp.correctChecksumAtBuild(true);
builder_tcp.correctLengthAtBuild(true);
builder_tcp.paddingAtBuild(true);
builder_tcp.ack(true);
builder_tcp.acknowledgmentNumber(ack);
//builder_tcp.checksum(tcpHeader.getChecksum());
//builder_tcp.dataOffset((byte)8);
builder_tcp.dstAddr(dstAddress);
builder_tcp.dstPort(new TcpPort( dstPort,""));
builder_tcp.fin(false);
//builder_tcp.options(tcpHeader.getOptions());
//builder_tcp.padding(tcpHeader.getPadding());
builder_tcp.psh(false);
builder_tcp.reserved((byte) 0);
builder_tcp.rst(false);
builder_tcp.sequenceNumber(sequence);
builder_tcp.srcAddr(srcAddress);
builder_tcp.srcPort(new TcpPort( srcPort,""));
builder_tcp.syn(false);
builder_tcp.urg(false);
//builder_tcp.urgentPointer(tcpHeader.getUrgentPointer());
builder_tcp.window( window);
IpV4Packet.Builder builder_ipv4=new IpV4Packet.Builder();
builder_ipv4.correctChecksumAtBuild(true);
builder_ipv4.correctLengthAtBuild(true);
builder_ipv4.dontFragmentFlag(true);
builder_ipv4.paddingAtBuild(true);
builder_ipv4.dstAddr(dstAddress);
builder_ipv4.fragmentOffset( (short)0);
//builder_ipv4.headerChecksum(ipV4Header.getHeaderChecksum());
//short identification= Math.abs(random.nextInt(Short.MAX_VALUE));
//identification=ident;
builder_ipv4.identification(ident);
builder_ipv4.ihl((byte) 5);
builder_ipv4.moreFragmentFlag(false);
//builder_ipv4.options(ipV4Header.getOptions());
//builder_ipv4.padding(ipV4Header.getPadding());
builder_ipv4.protocol(IpNumber.TCP);
//builder_ipv4.reservedFlag(ipV4Header.getReservedFlag());
builder_ipv4.srcAddr(srcAddress);
builder_ipv4.tos(IpV4Rfc1349Tos.newInstance((byte) 0));
//builder_ipv4.totalLength( 52);
builder_ipv4.ttl(ttl);
builder_ipv4.version(IpVersion.IPV4);
builder_ipv4.payloadBuilder(builder_tcp);
p = buildIpV4(srcAddress_mac,dstAddrress_mac,builder_ipv4);
return p;
}
示例5: createAck
import org.pcap4j.packet.namednumber.TcpPort; //导入依赖的package包/类
static Packet createAck(
MacAddress srcAddress_mac,
MacAddress dstAddrress_mac,
Inet4Address srcAddress,short srcPort,
Inet4Address dstAddress,short dstPort,
int ack_sequence,int sequence,short ident){
TcpPacket.Builder builder_tcp=new TcpPacket.Builder();
//builder_tcp.payloadBuilder(new UnknownPacket.Builder().rawData(new byte[0]));
builder_tcp.correctChecksumAtBuild(true);
builder_tcp.correctLengthAtBuild(true);
builder_tcp.paddingAtBuild(true);
builder_tcp.ack(true);
builder_tcp.acknowledgmentNumber(ack_sequence);
//builder_tcp.checksum(tcpHeader.getChecksum());
//builder_tcp.dataOffset((byte) 8);
builder_tcp.dstAddr(dstAddress);
builder_tcp.dstPort(new TcpPort( dstPort,""));
//builder_tcp.fin(tcpHeader.getFin());
builder_tcp.psh(false);
builder_tcp.reserved((byte) 0);
builder_tcp.rst(false);
builder_tcp.sequenceNumber(sequence);
builder_tcp.srcAddr(srcAddress);
builder_tcp.srcPort(new TcpPort( srcPort,""));
builder_tcp.syn(false);
builder_tcp.urg(false);
//builder_tcp.urgentPointer(tcpHeader.getUrgentPointer());
builder_tcp.window( window);
IpV4Packet.Builder builder_ipv4=new IpV4Packet.Builder();
builder_ipv4.correctChecksumAtBuild(true);
builder_ipv4.correctLengthAtBuild(true);
builder_ipv4.paddingAtBuild(true);
builder_ipv4.dstAddr(dstAddress);
builder_ipv4.dontFragmentFlag(true);
builder_ipv4.fragmentOffset( (short) 0);
//builder_ipv4.headerChecksum(ipV4Header.getHeaderChecksum());
//short identification= Math.abs(random.nextInt(Short.MAX_VALUE));
builder_ipv4.identification(ident);
builder_ipv4.ihl((byte) 5);
//builder_ipv4.moreFragmentFlag(ipV4Header.getMoreFragmentFlag());
//builder_ipv4.options(ipV4Header.getOptions());
//builder_ipv4.padding(ipV4Header.getPadding());
builder_ipv4.protocol(IpNumber.TCP);
// builder_ipv4.reservedFlag(ipV4Header.getReservedFlag());
builder_ipv4.srcAddr(srcAddress);
builder_ipv4.tos(IpV4Rfc1349Tos.newInstance((byte) 0));
//builder_ipv4.totalLength( 52);
builder_ipv4.ttl(ttl);
builder_ipv4.version(IpVersion.IPV4);
builder_ipv4.payloadBuilder(builder_tcp);
//
Packet p = buildIpV4(srcAddress_mac,dstAddrress_mac,builder_ipv4);
//System.out.println("自定义确认 "+" identification "+identification+" ack_sequence "+ack_sequence+" # "+tcpPacket.getHeader());
return p;
}
示例6: createAck
import org.pcap4j.packet.namednumber.TcpPort; //导入依赖的package包/类
static Packet createAck(
MacAddress srcAddress_mac,
MacAddress dstAddrress_mac,
Inet4Address srcAddress,short srcPort,
Inet4Address dstAddress,short dstPort,
int ack_sequence,int sequence,short ident){
TcpPacket.Builder builder_tcp=new TcpPacket.Builder();
//builder_tcp.payloadBuilder(new UnknownPacket.Builder().rawData(new byte[0]));
builder_tcp.correctChecksumAtBuild(true);
builder_tcp.correctLengthAtBuild(true);
builder_tcp.paddingAtBuild(true);
builder_tcp.ack(true);
builder_tcp.acknowledgmentNumber(ack_sequence);
//builder_tcp.checksum(tcpHeader.getChecksum());
//builder_tcp.dataOffset((byte) 8);
builder_tcp.dstAddr(dstAddress);
builder_tcp.dstPort(new TcpPort( dstPort,""));
//builder_tcp.fin(tcpHeader.getFin());
builder_tcp.psh(false);
builder_tcp.reserved((byte) 0);
builder_tcp.rst(false);
builder_tcp.sequenceNumber(sequence);
builder_tcp.srcAddr(srcAddress);
builder_tcp.srcPort(new TcpPort( srcPort,""));
builder_tcp.syn(false);
builder_tcp.urg(false);
//builder_tcp.urgentPointer(tcpHeader.getUrgentPointer());
builder_tcp.window( window);
IpV4Packet.Builder builder_ipv4=new IpV4Packet.Builder();
builder_ipv4.correctChecksumAtBuild(true);
builder_ipv4.correctLengthAtBuild(true);
builder_ipv4.paddingAtBuild(true);
builder_ipv4.dstAddr(dstAddress);
builder_ipv4.dontFragmentFlag(true);
builder_ipv4.fragmentOffset( (short) 0);
//builder_ipv4.headerChecksum(ipV4Header.getHeaderChecksum());
//short identification= Math.abs(random.nextInt(Short.MAX_VALUE));
builder_ipv4.identification(ident);
builder_ipv4.ihl((byte) 5);
//builder_ipv4.moreFragmentFlag(ipV4Header.getMoreFragmentFlag());
//builder_ipv4.options(ipV4Header.getOptions());
//builder_ipv4.padding(ipV4Header.getPadding());
builder_ipv4.protocol(IpNumber.TCP);
// builder_ipv4.reservedFlag(ipV4Header.getReservedFlag());
builder_ipv4.srcAddr(srcAddress);
builder_ipv4.tos(IpV4Rfc1349Tos.newInstance((byte) 0));
//builder_ipv4.totalLength( 52);
builder_ipv4.ttl(ttl);
builder_ipv4.version(IpVersion.IPV4);
builder_ipv4.payloadBuilder(builder_tcp);
//
Packet p = buildIpV4(srcAddress_mac,dstAddrress_mac,builder_ipv4);
return p;
}
示例7: setSrcPort
import org.pcap4j.packet.namednumber.TcpPort; //导入依赖的package包/类
/**
*
* @param srcPort
*/
public void setSrcPort(int srcPort) {
this.srcPort = TcpPort.getInstance((short) srcPort);
}
示例8: createDataPacket
import org.pcap4j.packet.namednumber.TcpPort; //导入依赖的package包/类
static Packet createDataPacket(
MacAddress srcAddress_mac,
MacAddress dstAddrress_mac,
Inet4Address srcAddress, short srcPort,
Inet4Address dstAddress, short dstPort,
int sequence, int ack, byte[] data, short ident) {
Packet p;
TcpPacket.Builder builder_tcp = new TcpPacket.Builder();
builder_tcp.payloadBuilder(new UnknownPacket.Builder().rawData(data));
builder_tcp.correctChecksumAtBuild(true);
builder_tcp.correctLengthAtBuild(true);
builder_tcp.paddingAtBuild(true);
builder_tcp.ack(true);
builder_tcp.acknowledgmentNumber(ack);
//builder_tcp.checksum(tcpHeader.getChecksum());
//builder_tcp.dataOffset((byte)8);
builder_tcp.dstAddr(dstAddress);
builder_tcp.dstPort(new TcpPort(dstPort, ""));
builder_tcp.fin(false);
//builder_tcp.options(tcpHeader.getOptions());
//builder_tcp.padding(tcpHeader.getPadding());
builder_tcp.psh(false);
builder_tcp.reserved((byte) 0);
builder_tcp.rst(false);
builder_tcp.sequenceNumber(sequence);
builder_tcp.srcAddr(srcAddress);
builder_tcp.srcPort(new TcpPort(srcPort, ""));
builder_tcp.syn(false);
builder_tcp.urg(false);
//builder_tcp.urgentPointer(tcpHeader.getUrgentPointer());
builder_tcp.window(window);
IpV4Packet.Builder builder_ipv4 = new IpV4Packet.Builder();
builder_ipv4.correctChecksumAtBuild(true);
builder_ipv4.correctLengthAtBuild(true);
builder_ipv4.dontFragmentFlag(true);
builder_ipv4.paddingAtBuild(true);
builder_ipv4.dstAddr(dstAddress);
builder_ipv4.fragmentOffset((short) 0);
//builder_ipv4.headerChecksum(ipV4Header.getHeaderChecksum());
//short identification= Math.abs(random.nextInt(Short.MAX_VALUE));
//identification=ident;
builder_ipv4.identification(ident);
builder_ipv4.ihl((byte) 5);
builder_ipv4.moreFragmentFlag(false);
//builder_ipv4.options(ipV4Header.getOptions());
//builder_ipv4.padding(ipV4Header.getPadding());
builder_ipv4.protocol(IpNumber.TCP);
//builder_ipv4.reservedFlag(ipV4Header.getReservedFlag());
builder_ipv4.srcAddr(srcAddress);
builder_ipv4.tos(IpV4Rfc1349Tos.newInstance((byte) 0));
//builder_ipv4.totalLength( 52);
builder_ipv4.ttl(ttl);
builder_ipv4.version(IpVersion.IPV4);
builder_ipv4.payloadBuilder(builder_tcp);
p = buildIpV4(srcAddress_mac, dstAddrress_mac, builder_ipv4);
return p;
}
示例9: createAck
import org.pcap4j.packet.namednumber.TcpPort; //导入依赖的package包/类
static Packet createAck(
MacAddress srcAddress_mac,
MacAddress dstAddrress_mac,
Inet4Address srcAddress, short srcPort,
Inet4Address dstAddress, short dstPort,
int ack_sequence, int sequence, short ident) {
TcpPacket.Builder builder_tcp = new TcpPacket.Builder();
//builder_tcp.payloadBuilder(new UnknownPacket.Builder().rawData(new byte[0]));
builder_tcp.correctChecksumAtBuild(true);
builder_tcp.correctLengthAtBuild(true);
builder_tcp.paddingAtBuild(true);
builder_tcp.ack(true);
builder_tcp.acknowledgmentNumber(ack_sequence);
//builder_tcp.checksum(tcpHeader.getChecksum());
//builder_tcp.dataOffset((byte) 8);
builder_tcp.dstAddr(dstAddress);
builder_tcp.dstPort(new TcpPort(dstPort, ""));
//builder_tcp.fin(tcpHeader.getFin());
builder_tcp.psh(false);
builder_tcp.reserved((byte) 0);
builder_tcp.rst(false);
builder_tcp.sequenceNumber(sequence);
builder_tcp.srcAddr(srcAddress);
builder_tcp.srcPort(new TcpPort(srcPort, ""));
builder_tcp.syn(false);
builder_tcp.urg(false);
//builder_tcp.urgentPointer(tcpHeader.getUrgentPointer());
builder_tcp.window(window);
IpV4Packet.Builder builder_ipv4 = new IpV4Packet.Builder();
builder_ipv4.correctChecksumAtBuild(true);
builder_ipv4.correctLengthAtBuild(true);
builder_ipv4.paddingAtBuild(true);
builder_ipv4.dstAddr(dstAddress);
builder_ipv4.dontFragmentFlag(true);
builder_ipv4.fragmentOffset((short) 0);
//builder_ipv4.headerChecksum(ipV4Header.getHeaderChecksum());
//short identification= Math.abs(random.nextInt(Short.MAX_VALUE));
builder_ipv4.identification(ident);
builder_ipv4.ihl((byte) 5);
//builder_ipv4.moreFragmentFlag(ipV4Header.getMoreFragmentFlag());
//builder_ipv4.options(ipV4Header.getOptions());
//builder_ipv4.padding(ipV4Header.getPadding());
builder_ipv4.protocol(IpNumber.TCP);
// builder_ipv4.reservedFlag(ipV4Header.getReservedFlag());
builder_ipv4.srcAddr(srcAddress);
builder_ipv4.tos(IpV4Rfc1349Tos.newInstance((byte) 0));
//builder_ipv4.totalLength( 52);
builder_ipv4.ttl(ttl);
builder_ipv4.version(IpVersion.IPV4);
builder_ipv4.payloadBuilder(builder_tcp);
//System.out.println("自定义确认 "+" identification "+identification+" ack_sequence "+ack_sequence+" # "+tcpPacket
// .getHeader());
return buildIpV4(srcAddress_mac, dstAddrress_mac, builder_ipv4);
}
示例10: setDstPort
import org.pcap4j.packet.namednumber.TcpPort; //导入依赖的package包/类
/**
*
* @param dstPort
*/
public void setDstPort(int dstPort) {
this.dstPort = TcpPort.getInstance((short) dstPort);
}
示例11: getSrcPort
import org.pcap4j.packet.namednumber.TcpPort; //导入依赖的package包/类
/**
*
* @return
*/
public TcpPort getSrcPort() {
return srcPort;
}
示例12: getDstPort
import org.pcap4j.packet.namednumber.TcpPort; //导入依赖的package包/类
/**
*
* @return
*/
public TcpPort getDstPort() {
return dstPort;
}