net.fs.utils.MLog Java Examples

The following examples show how to use net.fs.utils.MLog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientManager.java    From NSS with Apache License 2.0 6 votes vote down vote up
void scanClientControl(){
		Iterator<Integer> it=getClientTableIterator();
		long current=System.currentTimeMillis();
		//MLog.println("ffffffffffff "+clientTable.size());
		while(it.hasNext()){
			ClientControl cc=clientTable.get(it.next());
			if(cc!=null){
				if(current-cc.getLastReceivePingTime()<receivePingTimeout){
					if(current-cc.getLastSendPingTime()>sendPingInterval){
						cc.sendPingMessage();
					}
				}else {
					//超时关闭client
					MLog.println("超时关闭Client  "+cc.dstIp.getHostAddress()+":"+cc.dstPort+" "+new Date());
//					System.exit(0);
					synchronized (syn_clientTable) {
						cc.close();
					}
				}
			}
		}
	}
 
Example #2
Source File: TunManager.java    From finalspeed-91yun with GNU General Public License v2.0 6 votes vote down vote up
void scan(){
	Iterator<String> it=getConnTableIterator();
	while(it.hasNext()){
		String key=it.next();
		TCPTun tun=connTable.get(key);
		if(tun!=null){
			if(tun.preDataReady){
				//无数据超时
				long t=System.currentTimeMillis()-tun.lastReceiveDataTime;
				if(t>6000){
					connTable.remove(key);
					if(capEnv.client){
						defaultTcpTun=null;
						MLog.println("tcp隧道超时");
					}
				}
			}else{
				//连接中超时
				if(System.currentTimeMillis()-tun.createTime>5000){
					connTable.remove(key);
				}
			}
		}
	}
}
 
Example #3
Source File: CapEnv.java    From finalspeed-91yun with GNU General Public License v2.0 6 votes vote down vote up
IpV4Packet getIpV4Packet_pppoe(EthernetPacket packet_eth) throws IllegalRawDataException{
	IpV4Packet ipV4Packet=null;
	byte[] pppData=packet_eth.getPayload().getRawData();
	if(pppData.length>8&&pppData[8]==0x45){
		byte[] b2=new byte[2];
		System.arraycopy(pppData, 4, b2, 0, 2);
		short len=(short) ByteShortConvert.toShort(b2, 0);
		int ipLength=toUnsigned(len)-2;
		byte[] ipData=new byte[ipLength];
		//设置ppp参数
		PacketUtils.pppHead_static[2]=pppData[2];
		PacketUtils.pppHead_static[3]=pppData[3];
		if(ipLength==(pppData.length-8)){
			System.arraycopy(pppData, 8, ipData, 0, ipLength);
			ipV4Packet=IpV4Packet.newPacket(ipData, 0, ipData.length);
		}else {
			MLog.println("长度不符!");
		}
	}
	return ipV4Packet;
}
 
Example #4
Source File: TCPTun.java    From finalspeed-91yun with GNU General Public License v2.0 6 votes vote down vote up
TCPTun(CapEnv capEnv,
		Inet4Address serverAddress,short serverPort,
		MacAddress srcAddress_mac,MacAddress dstAddrress_mac){
	this.capEnv=capEnv;
	sendHandle=capEnv.sendHandle;
	this.remoteAddress=serverAddress;
	this.remotePort=serverPort;
	localAddress=capEnv.local_ipv4;
	localPort=(short)(random.nextInt(64*1024-1-10000)+10000);
	Packet syncPacket=null;
	try {
		syncPacket = PacketUtils.createSync(srcAddress_mac, dstAddrress_mac, localAddress, localPort,serverAddress, serverPort, localStartSequence,getIdent());
		try {
			sendHandle.sendPacket(syncPacket);
			localSequence=localStartSequence+1;
		} catch (Exception e) {
			e.printStackTrace();
		}
	} catch (Exception e1) {
		e1.printStackTrace();
	}
	MLog.println("发送第一次握手 "+" ident "+localIdent);
	MLog.println(""+syncPacket);
	
}
 
Example #5
Source File: ClientManager.java    From finalspeed-91yun with GNU General Public License v2.0 6 votes vote down vote up
void scanClientControl(){
		Iterator<Integer> it=getClientTableIterator();
		long current=System.currentTimeMillis();
		//MLog.println("ffffffffffff "+clientTable.size());
		while(it.hasNext()){
			ClientControl cc=clientTable.get(it.next());
			if(cc!=null){
				if(current-cc.getLastReceivePingTime()<receivePingTimeout){
					if(current-cc.getLastSendPingTime()>sendPingInterval){
						cc.sendPingMessage();
					}
				}else {
					//超时关闭client
					MLog.println("超时关闭client "+cc.dstIp.getHostAddress()+":"+cc.dstPort+" "+new Date());
//					System.exit(0);
					synchronized (syn_clientTable) {
						cc.close();
					}
				}
			}
		}
	}
 
Example #6
Source File: ClientUI.java    From finalspeed with GNU General Public License v2.0 6 votes vote down vote up
void checkQuanxian() {
        if (systemName.contains("windows")) {
            boolean b;
            File file = new File(System.getenv("WINDIR") + "\\test.file");
            //System.out.println("kkkkkkk "+file.getAbsolutePath());
            try {
                //noinspection ResultOfMethodCallIgnored
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
            b = file.exists();
            //noinspection ResultOfMethodCallIgnored
            file.delete();

            if (!b) {
                //mainFrame.setVisible(true);
                if (isVisible) {
                    JOptionPane.showMessageDialog(null, "请以管理员身份运行! ");
                }
                MLog.println("请以管理员身份运行,否则可能无法正常工作! ");
//                System.exit(0);
            }
        }
    }
 
Example #7
Source File: ClientUI.java    From finalspeed-91yun with GNU General Public License v2.0 6 votes vote down vote up
void checkQuanxian() {
        if (systemName.contains("windows")) {
            boolean b = false;
            File file = new File(System.getenv("WINDIR") + "\\test.file");
            //System.out.println("kkkkkkk "+file.getAbsolutePath());
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
            b = file.exists();
            file.delete();

            if (!b) {
                //mainFrame.setVisible(true);
                if (isVisible) {
                    JOptionPane.showMessageDialog(null, "请以管理员身份运行! ");
                }
                MLog.println("请以管理员身份运行,否则可能无法正常工作! ");
//                System.exit(0);
            }
        }
    }
 
Example #8
Source File: TCPTun.java    From finalspeed with GNU General Public License v2.0 6 votes vote down vote up
TCPTun(CapEnv capEnv,
       Inet4Address serverAddress, short serverPort,
       MacAddress srcAddress_mac, MacAddress dstAddrress_mac) {
    this.capEnv = capEnv;
    sendHandle = capEnv.sendHandle;
    this.remoteAddress = serverAddress;
    this.remotePort = serverPort;
    localAddress = capEnv.local_ipv4;
    localPort = (short) (random.nextInt(64 * 1024 - 1 - 10000) + 10000);
    Packet syncPacket = null;
    try {
        syncPacket = PacketUtils.createSync(srcAddress_mac, dstAddrress_mac, localAddress, localPort,
                serverAddress, serverPort, localStartSequence, getIdent());
        try {
            sendHandle.sendPacket(syncPacket);
            localSequence = localStartSequence + 1;
        } catch (Exception e) {
            e.printStackTrace();
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    MLog.println("发送第一次握手 " + " ident " + localIdent);
    MLog.println("" + syncPacket);

}
 
Example #9
Source File: CapEnv.java    From NSS with Apache License 2.0 6 votes vote down vote up
IpV4Packet getIpV4Packet_pppoe(EthernetPacket packet_eth) throws IllegalRawDataException {
	IpV4Packet ipV4Packet=null;
	byte[] pppData=packet_eth.getPayload().getRawData();
	if(pppData.length>8&&pppData[8]==0x45){
		byte[] b2=new byte[2];
		System.arraycopy(pppData, 4, b2, 0, 2);
		short len=(short) ByteShortConvert.toShort(b2, 0);
		int ipLength=toUnsigned(len)-2;
		byte[] ipData=new byte[ipLength];
		//设置ppp参数
		PacketUtils.pppHead_static[2]=pppData[2];
		PacketUtils.pppHead_static[3]=pppData[3];
		if(ipLength==(pppData.length-8)){
			System.arraycopy(pppData, 8, ipData, 0, ipLength);
			ipV4Packet= IpV4Packet.newPacket(ipData, 0, ipData.length);
		}else {
			MLog.println("长度不符!");
		}
	}
	return ipV4Packet;
}
 
Example #10
Source File: TunManager.java    From NSS with Apache License 2.0 6 votes vote down vote up
void scan(){
	Iterator<String> it=getConnTableIterator();
	while(it.hasNext()){
		String key=it.next();
		TCPTun tun=connTable.get(key);
		if(tun!=null){
			if(tun.preDataReady){
				//无数据超时
				long t=System.currentTimeMillis()-tun.lastReceiveDataTime;
				if(t>6000){
					connTable.remove(key);
					if(capEnv.client){
						defaultTcpTun=null;
						MLog.println("tcp隧道超时");
					}
				}
			}else{
				//连接中超时
				if(System.currentTimeMillis()-tun.createTime>5000){
					connTable.remove(key);
				}
			}
		}
	}
}
 
Example #11
Source File: TunManager.java    From finalspeed with GNU General Public License v2.0 6 votes vote down vote up
void scan() {
    CopiedIterator<String> it = getConnTableIterator();
    while (it.hasNext()) {
        String key = it.next();
        TCPTun tun = connTable.get(key);
        if (tun != null) {
            if (tun.preDataReady) {
                //无数据超时
                long t = System.currentTimeMillis() - tun.lastReceiveDataTime;
                if (t > 6000) {
                    connTable.remove(key);
                    if (capEnv.client) {
                        defaultTcpTun = null;
                        MLog.println("tcp隧道超时");
                    }
                }
            } else {
                //连接中超时
                if (System.currentTimeMillis() - tun.createTime > 5000) {
                    connTable.remove(key);
                }
            }
        }
    }
}
 
Example #12
Source File: CapEnv.java    From finalspeed with GNU General Public License v2.0 6 votes vote down vote up
IpV4Packet getIpV4Packet_pppoe(EthernetPacket packet_eth) throws IllegalRawDataException {
    IpV4Packet ipV4Packet = null;
    byte[] pppData = packet_eth.getPayload().getRawData();
    if (pppData.length > 8 && pppData[8] == 0x45) {
        byte[] b2 = new byte[2];
        System.arraycopy(pppData, 4, b2, 0, 2);
        short len = ByteShortConvert.toShort(b2, 0);
        int ipLength = toUnsigned(len) - 2;
        byte[] ipData = new byte[ipLength];
        //设置ppp参数
        PacketUtils.pppHead_static[2] = pppData[2];
        PacketUtils.pppHead_static[3] = pppData[3];
        if (ipLength == (pppData.length - 8)) {
            System.arraycopy(pppData, 8, ipData, 0, ipLength);
            ipV4Packet = IpV4Packet.newPacket(ipData, 0, ipData.length);
        } else {
            MLog.println("长度不符!");
        }
    }
    return ipV4Packet;
}
 
Example #13
Source File: ClientManager.java    From finalspeed with GNU General Public License v2.0 6 votes vote down vote up
void scanClientControl() {
        CopiedIterator<Integer> it = getClientTableIterator();
        long current = System.currentTimeMillis();
        //MLog.println("ffffffffffff "+clientTable.size());
        while (it.hasNext()) {
            ClientControl cc = clientTable.get(it.next());
            if (cc != null) {
                if (current - cc.getLastReceivePingTime() < receivePingTimeout) {
                    if (current - cc.getLastSendPingTime() > sendPingInterval) {
                        cc.sendPingMessage();
                    }
                } else {
                    //超时关闭client
                    MLog.println("超时关闭client " + cc.dstIp.getHostAddress() + ":" + cc.dstPort + " " + new Date());
//					System.exit(0);
                    synchronized (syn_clientTable) {
                        cc.close();
                    }
                }
            }
        }
    }
 
Example #14
Source File: ClientUI.java    From NSS with Apache License 2.0 6 votes vote down vote up
void checkQuanxian() {
    if (systemName.contains("windows")) {
        boolean b = false;
        File file = new File(System.getenv("WINDIR") + "\\test.file");
        System.out.println("auth : "+file.getAbsolutePath());
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        b = file.exists();
        file.delete();

        if (!b) {
            //mainFrame.setVisible(true);
            if (isVisible) {
                JOptionPane.showMessageDialog(null, "请以管理员身份运行! ");
            }
            MLog.println("请以管理员身份运行,否则可能无法正常工作! ");
            System.exit(0);
        }
    }
}
 
Example #15
Source File: ConnectionUDP.java    From finalspeed with GNU General Public License v2.0 5 votes vote down vote up
public ConnectionUDP(Route ro, InetAddress dstIp, int dstPort, int mode, int connectId, ClientControl
        clientControl) throws Exception {
    this.clientControl = clientControl;
    this.route = ro;
    this.dstIp = dstIp;
    this.dstPort = dstPort;
    this.mode = mode;
    if (mode == 1) {
        MLog.println("                 发起连接RUDP " + dstIp + ":" + dstPort + " connectId " + connectId);
    } else if (mode == 2) {
        MLog.println("                 接受连接RUDP " + dstIp + ":" + dstPort + " connectId " + connectId);
    }
    this.connectId = connectId;
    try {
        sender = new Sender(this);
        receiver = new Receiver(this);
        uos = new UDPOutputStream(this);
        uis = new UDPInputStream(this);
        if (mode == 2) {
            ro.createTunnelProcessor().process(this);
        }
    } catch (Exception e) {
        e.printStackTrace();
        connected = false;
        route.connTable.remove(connectId);
        e.printStackTrace();
        MLog.println("                 连接失败RUDP " + connectId);
        synchronized (this) {
            notifyAll();
        }
        throw e;
    }
    MLog.println("                 连接成功RUDP " + connectId);
    synchronized (this) {
        notifyAll();
    }
}
 
Example #16
Source File: FSServer.java    From finalspeed with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        FSServer fs = new FSServer();
    } catch (Exception e) {
        e.printStackTrace();
        if (e instanceof BindException) {
            MLog.println("Udp port already in use.");
        }
        MLog.println("Start failed.");
        System.exit(0);
    }
}
 
Example #17
Source File: Pipe.java    From finalspeed with GNU General Public License v2.0 5 votes vote down vote up
public void pipe(UDPInputStream tis, OutputStream os, int maxSpeed, ConnectionUDP conn) throws Exception {
    int len;
    byte[] buf = new byte[1000];
    boolean sended = false;
    boolean sendedb = false;
    int n = 0;
    boolean msged = false;
    while ((len = tis.read(buf, 0, buf.length)) > 0) {
        readedLength += len;
        if (!sendedb) {
            pv = buf;
            pvl = len;
            sendedb = true;
        }
        if (dstPort > 0) {
            if (ClientUI.ui != null) {
                if (!msged) {
                    msged = true;
                    String msg = "端口" + dstPort + "连接成功";
                    ClientUI.ui.setMessage(msg);
                    MLog.println(msg);
                }

            }
        }
        os.write(buf, 0, len);
        if (!sended) {
            sended = true;
        }
    }
}
 
Example #18
Source File: FSServer.java    From finalspeed-91yun with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
	try {
		FSServer fs = new FSServer();
	} catch (Exception e) {
		e.printStackTrace();
		if(e instanceof BindException){
			MLog.println("Udp port already in use.");
		}
		MLog.println("Start failed.");
		System.exit(0);
	}
}
 
Example #19
Source File: Pipe.java    From finalspeed-91yun with GNU General Public License v2.0 5 votes vote down vote up
public void pipe(UDPInputStream tis,OutputStream os,int maxSpeed,ConnectionUDP conn) throws Exception{
	int len=0;
	byte[] buf=new byte[1000];
	boolean sended=false;
	boolean sendedb=false;
	int n=0;
	boolean msged=false;
	while((len=tis.read(buf, 0, buf.length))>0){
		readedLength+=len;
		if(!sendedb){
			pv=buf;
			pvl=len;
			sendedb=true;
		}
		if(dstPort>0){
			if(ClientUI.ui!=null){
				if(!msged){
					msged=true;
					String msg="端口"+dstPort+"连接成功";
					ClientUI.ui.setMessage(msg);
					MLog.println(msg);
				}
				
			}
		}
		os.write(buf, 0, len);
		if(!sended){
			sended=true;
		}
	}
}
 
Example #20
Source File: TCPTun.java    From NSS with Apache License 2.0 5 votes vote down vote up
TCPTun(CapEnv capEnv,
          Inet4Address serverAddress, short serverPort,
          MacAddress srcAddress_mac, MacAddress dstAddrress_mac){
	this.capEnv=capEnv;
	sendHandle=capEnv.sendHandle;
	this.remoteAddress=serverAddress;
	this.remotePort=serverPort;
	localAddress=capEnv.local_ipv4;
	localPort=(short)(random.nextInt(64*1024-1-10000)+10000);
	Packet syncPacket=null;
	try {
		syncPacket = PacketUtils.createSync(srcAddress_mac, dstAddrress_mac, localAddress, localPort,serverAddress, serverPort, localStartSequence,getIdent());
		try {
			sendHandle.sendPacket(syncPacket);
			localSequence=localStartSequence+1;
		} catch (Exception e) {
			e.printStackTrace();
		}
	} catch (Exception e1) {
		e1.printStackTrace();
	}
	MLog.println("发送第一次握手 "+" ident "+localIdent);
	MLog.println(""+syncPacket);
	
}
 
Example #21
Source File: FSServer.java    From NSS with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	try {
		FSServer fs = new FSServer();
	} catch (Exception e) {
		e.printStackTrace();
		if(e instanceof BindException){
			MLog.println("Udp port already in use.");
		}
		MLog.println("Start failed.");
		System.exit(0);
	}
}
 
Example #22
Source File: TCPTun.java    From finalspeed-91yun with GNU General Public License v2.0 4 votes vote down vote up
public void process_server(final Packet packet,EthernetHeader ethernetHeader,IpV4Header ipV4Header,TcpPacket tcpPacket,boolean client){
	TcpHeader tcpHeader=tcpPacket.getHeader();
	
	if(!preDataReady){
		if(!connectReady){
			//第一次握手
			dstMacaAddress=ethernetHeader.getSrcAddr();
			if(tcpHeader.getSyn()&&!tcpHeader.getAck()){
				remoteStartSequence=tcpHeader.getSequenceNumber();
				remoteSequence=remoteStartSequence+1;
				remoteSequence_max=remoteSequence;
				MLog.println("接收第一次握手 "+remoteAddress.getHostAddress()+":"+remotePort+"->"+localAddress.getHostAddress()+":"+localPort+" ident "+ipV4Header.getIdentification());
				MLog.println(""+packet);
				Packet responePacket=PacketUtils.createSyncAck(
						capEnv.local_mac,
						capEnv.gateway_mac,
						localAddress,(short)localPort,
						ipV4Header.getSrcAddr(),tcpHeader.getSrcPort().value(),
						tcpHeader.getSequenceNumber()+1,localStartSequence,(short)0
						);
				try {
					sendHandle.sendPacket(responePacket);
				} catch (Exception e) {
					e.printStackTrace();
				}
				localSequence=localStartSequence+1;
				MLog.println("发送第二次握手 "+capEnv.local_mac+"->"+capEnv.gateway_mac+" "+localAddress+"->"+" ident "+0);

				MLog.println(""+responePacket);
			}

			if(!tcpHeader.getSyn()&&tcpHeader.getAck()){
				if(tcpPacket.getPayload()==null){
					//第三次握手,客户端确认
					if(tcpHeader.getAcknowledgmentNumber()==localSequence){
						MLog.println("接收第三次握手 "+" ident "+ipV4Header.getIdentification());
						MLog.println(packet+"");
						Thread t1=new Thread(){
							public void run(){
								//startSend(basePacket_server,syc_sequence_client+1);
							}
						};
						//t1.start();
						connectReady=true;
					}
				}
				//MLog.println("客户端响应preview\n "+packet);
				//MLog.println("request "+tcp.ack());
				sendedTable_server.remove(tcpHeader.getAcknowledgmentNumber());
				boolean selfAck=selfAckTable.contains(ipV4Header.getIdentification());
				//MLog.println("客户端确认 "+"selfack "+selfAck+" id "+ipV4Header.getIdentification()+" ack_sequence "+tcpHeader.getAcknowledgmentNumberAsLong()+" "+sendedTable_server.size()+"ppppppp "+tcpHeader);
			}
			
		}else {
			if(tcpPacket.getPayload()!=null){
				preDataReady=true;
				onReceiveDataPacket( tcpPacket, tcpHeader, ipV4Header );
				byte[] sim=getSimResponeHead();
				sendData(sim);
			}
		}
	}else {
		if(tcpPacket.getPayload()!=null){
			onReceiveDataPacket( tcpPacket, tcpHeader, ipV4Header );
			TunData td=new TunData();
			td.tun=this;
			td.data=tcpPacket.getPayload().getRawData();
			capEnv.vDatagramSocket.onReceinveFromTun(td);
		}
	}
	if(tcpHeader.getRst()){
		MLog.println("reset packet "+ipV4Header.getIdentification()+" "+tcpHeader.getSequenceNumber()+" "+remoteAddress.getHostAddress()+":"+remotePort+"->"+localAddress.getHostAddress()+":"+localPort+" "+" ident "+ipV4Header.getIdentification());
	}

}
 
Example #23
Source File: CapEnv.java    From finalspeed-91yun with GNU General Public License v2.0 4 votes vote down vote up
public void setListenPort(short listenPort) {
	this.listenPort = listenPort;
	if(!client){
		MLog.info("Listen tcp port: "+toUnsigned(listenPort));
	}
}
 
Example #24
Source File: FSServer.java    From finalspeed-91yun with GNU General Public License v2.0 4 votes vote down vote up
public FSServer() throws Exception {
	MLog.info("");
	MLog.info("FinalSpeed server starting... ");
	MLog.info("System Name: " + systemName);
	udpServer = this;
	final MapTunnelProcessor mp = new MapTunnelProcessor();

	String port_s = readFileData("./cnf/listen_port");
	if (port_s != null && !port_s.trim().equals("")) {
		port_s = port_s.replaceAll("\n", "").replaceAll("\r", "");
		routePort = Integer.parseInt(port_s);
	}
	route_udp = new Route(mp.getClass().getName(), (short) routePort, Route.mode_server, false,true);
	if (systemName.equals("linux")) {
		startFirewall_linux();
		setFireWall_linux_udp();
	}else if(systemName.contains("windows")){
		startFirewall_windows();
	}

	Route.es.execute(new Runnable() {

		@Override
		public void run() {
			try {
				route_tcp = new Route(mp.getClass().getName(), (short) routePort, Route.mode_server, true,true);
				if (systemName.equals("linux")) {
					setFireWall_linux_tcp();
				}else if(systemName.contains("windows")){
					if(success_firewall_windows){
						setFireWall_windows_tcp();
					}else{
						System.out.println("启动windows防火墙失败,请先运行防火墙服务.");
					}
				}
			} catch (Exception e) {
				// e.printStackTrace();
			}
		}
	});

}
 
Example #25
Source File: FSServer.java    From finalspeed with GNU General Public License v2.0 4 votes vote down vote up
public FSServer() throws Exception {
    MLog.info("");
    MLog.info("FinalSpeed server starting... ");
    MLog.info("System Name: " + systemName);
    udpServer = this;
    final MapTunnelProcessor mp = new MapTunnelProcessor();

    String port_s = readFileData("./cnf/listen_port");
    if (port_s != null && !port_s.trim().equals("")) {
        port_s = port_s.replaceAll("\n", "").replaceAll("\r", "");
        routePort = Integer.parseInt(port_s);
    }
    route_udp = new Route(mp.getClass().getName(), (short) routePort, Route.mode_server, false, true);
    if (systemName.equals("linux")) {
        startFirewall_linux();
        setFireWall_linux_udp();
    } else if (systemName.contains("windows")) {
        startFirewall_windows();
    }

    Route.es.execute(new Runnable() {

        @Override
        public void run() {
            try {
                route_tcp = new Route(mp.getClass().getName(), (short) routePort, Route.mode_server, true, true);
                if (systemName.equals("linux")) {
                    setFireWall_linux_tcp();
                } else if (systemName.contains("windows")) {
                    if (success_firewall_windows) {
                        setFireWall_windows_tcp();
                    } else {
                        System.out.println("启动windows防火墙失败,请先运行防火墙服务.");
                    }
                }
            } catch (Exception e) {
                // e.printStackTrace();
            }
        }
    });

}
 
Example #26
Source File: ClientControl.java    From NSS with Apache License 2.0 4 votes vote down vote up
public void onReceivePing(PingMessage pm){
	if(route.mode==2){
		currentSpeed=pm.getDownloadSpeed()*1024;
		MLog.println("更新对方速度: "+currentSpeed);
	}
}
 
Example #27
Source File: CapEnv.java    From NSS with Apache License 2.0 4 votes vote down vote up
public void setListenPort(short listenPort) {
	this.listenPort = listenPort;
	if(!client){
		MLog.info("Listen tcp port: "+toUnsigned(listenPort));
	}
}
 
Example #28
Source File: TCPTun.java    From finalspeed with GNU General Public License v2.0 4 votes vote down vote up
public void process_server(final Packet packet, EthernetHeader ethernetHeader, IpV4Header ipV4Header, TcpPacket
        tcpPacket, boolean client) {
    TcpHeader tcpHeader = tcpPacket.getHeader();

    if (!preDataReady) {
        if (!connectReady) {
            //第一次握手
            dstMacaAddress = ethernetHeader.getSrcAddr();
            if (tcpHeader.getSyn() && !tcpHeader.getAck()) {
                remoteStartSequence = tcpHeader.getSequenceNumber();
                remoteSequence = remoteStartSequence + 1;
                remoteSequence_max = remoteSequence;
                MLog.println("接收第一次握手 " + remoteAddress.getHostAddress() + ":" + remotePort + "->" + localAddress
                        .getHostAddress() + ":" + localPort + " ident " + ipV4Header.getIdentification());
                MLog.println("" + packet);
                Packet responePacket = PacketUtils.createSyncAck(
                        capEnv.local_mac,
                        capEnv.gateway_mac,
                        localAddress, localPort,
                        ipV4Header.getSrcAddr(), tcpHeader.getSrcPort().value(),
                        tcpHeader.getSequenceNumber() + 1, localStartSequence, (short) 0
                );
                try {
                    sendHandle.sendPacket(responePacket);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                localSequence = localStartSequence + 1;
                MLog.println("发送第二次握手 " + capEnv.local_mac + "->" + capEnv.gateway_mac + " " + localAddress +
                        "->" + " ident " + 0);

                MLog.println("" + responePacket);
            }

            if (!tcpHeader.getSyn() && tcpHeader.getAck()) {
                if (tcpPacket.getPayload() == null) {
                    //第三次握手,客户端确认
                    if (tcpHeader.getAcknowledgmentNumber() == localSequence) {
                        MLog.println("接收第三次握手 " + " ident " + ipV4Header.getIdentification());
                        MLog.println(packet + "");
                        Thread t1 = new Thread() {
                            public void run() {
                                //startSend(basePacket_server,syc_sequence_client+1);
                            }
                        };
                        //t1.start();
                        connectReady = true;
                    }
                }
                //MLog.println("客户端响应preview\n "+packet);
                //MLog.println("request "+tcp.ack());
                sendedTable_server.remove(tcpHeader.getAcknowledgmentNumber());
                boolean selfAck = selfAckTable.contains(ipV4Header.getIdentification());
                //MLog.println("客户端确认 "+"selfack "+selfAck+" id "+ipV4Header.getIdentification()+" ack_sequence
                // "+tcpHeader.getAcknowledgmentNumberAsLong()+" "+sendedTable_server.size()+"ppppppp "+tcpHeader);
            }

        } else {
            if (tcpPacket.getPayload() != null) {
                preDataReady = true;
                onReceiveDataPacket(tcpPacket, tcpHeader, ipV4Header);
                byte[] sim = getSimResponeHead();
                sendData(sim);
            }
        }
    } else {
        if (tcpPacket.getPayload() != null) {
            onReceiveDataPacket(tcpPacket, tcpHeader, ipV4Header);
            TunData td = new TunData();
            td.tun = this;
            td.data = tcpPacket.getPayload().getRawData();
            capEnv.vDatagramSocket.onReceinveFromTun(td);
        }
    }
    if (tcpHeader.getRst()) {
        MLog.println("reset packet " + ipV4Header.getIdentification() + " " + tcpHeader.getSequenceNumber() + " "
                + remoteAddress.getHostAddress() + ":" + remotePort + "->" + localAddress.getHostAddress() + ":" +
                localPort + " " + " ident " + ipV4Header.getIdentification());
    }

}
 
Example #29
Source File: TCPTun.java    From finalspeed with GNU General Public License v2.0 4 votes vote down vote up
public void process_client(CapEnv capEnv, final Packet packet, EthernetHeader ethernetHeader, IpV4Header
        ipV4Header, TcpPacket tcpPacket, boolean client) {

    TcpHeader tcpHeader = tcpPacket.getHeader();
    if (!preDataReady) {
        if (!connectReady) {
            if (tcpHeader.getAck() && tcpHeader.getSyn()) {
                if (tcpHeader.getAcknowledgmentNumber() == (localStartSequence + 1)) {
                    MLog.println("接收第二次握手 " + " ident " + ipV4Header.getIdentification());
                    MLog.println("" + packet);
                    remoteStartSequence = tcpHeader.getSequenceNumber();
                    remoteSequence = remoteStartSequence + 1;
                    remoteSequence_max = remoteSequence;
                    Packet p3 = PacketUtils.createAck(capEnv.local_mac, capEnv.gateway_mac, capEnv.local_ipv4,
                            localPort, remoteAddress, remotePort, remoteSequence, localSequence, getIdent());
                    try {
                        sendHandle.sendPacket(p3);
                        MLog.println("发送第三次握手 " + " ident " + localIdent);
                        MLog.println("" + p3);
                        connectReady = true;

                        byte[] sim = getSimRequestHead(remotePort);
                        sendData(sim);
                        MLog.println("发送请求 " + " ident " + localIdent);
                    } catch (PcapNativeException | NotOpenException e) {
                        e.printStackTrace();
                    }
                }
            }
        } else {
            if (tcpPacket.getPayload() != null) {
                preDataReady = true;
                onReceiveDataPacket(tcpPacket, tcpHeader, ipV4Header);
                MLog.println("接收响应 " + " ident " + ipV4Header.getIdentification());
            }
        }

    } else {
        if (tcpPacket.getPayload() != null) {
            //MLog.println("客户端正式接收数据 "+capClientEnv.vDatagramSocket);
            onReceiveDataPacket(tcpPacket, tcpHeader, ipV4Header);
            TunData td = new TunData();
            td.tun = this;
            td.data = tcpPacket.getPayload().getRawData();
            capEnv.vDatagramSocket.
                    onReceinveFromTun(td);
        }
    }
    if (tcpHeader.getRst()) {
        MLog.println("reset packet " + ipV4Header.getIdentification() + " " + tcpHeader.getSequenceNumber() + " "
                + remoteAddress.getHostAddress() + ":" + remotePort + "->" + localAddress.getHostAddress() + ":" +
                localPort);
    }

}
 
Example #30
Source File: TCPTun.java    From NSS with Apache License 2.0 4 votes vote down vote up
public void process_server(final Packet packet, EthernetHeader ethernetHeader, IpV4Header ipV4Header, TcpPacket tcpPacket, boolean client){
	TcpHeader tcpHeader=tcpPacket.getHeader();
	
	if(!preDataReady){
		if(!connectReady){
			//第一次握手
			dstMacaAddress=ethernetHeader.getSrcAddr();
			if(tcpHeader.getSyn()&&!tcpHeader.getAck()){
				remoteStartSequence=tcpHeader.getSequenceNumber();
				remoteSequence=remoteStartSequence+1;
				remoteSequence_max=remoteSequence;
				MLog.println("接收第一次握手 "+remoteAddress.getHostAddress()+":"+remotePort+"->"+localAddress.getHostAddress()+":"+localPort+" ident "+ipV4Header.getIdentification());
				MLog.println(""+packet);
				Packet responePacket=PacketUtils.createSyncAck(
						capEnv.local_mac,
						capEnv.gateway_mac,
						localAddress,(short)localPort,
						ipV4Header.getSrcAddr(),tcpHeader.getSrcPort().value(),
						tcpHeader.getSequenceNumber()+1,localStartSequence,(short)0
						);
				try {
					sendHandle.sendPacket(responePacket);
				} catch (Exception e) {
					e.printStackTrace();
				}
				localSequence=localStartSequence+1;
				MLog.println("发送第二次握手 "+capEnv.local_mac+"->"+capEnv.gateway_mac+" "+localAddress+"->"+" ident "+0);

				MLog.println(""+responePacket);
			}

			if(!tcpHeader.getSyn()&&tcpHeader.getAck()){
				if(tcpPacket.getPayload()==null){
					//第三次握手,客户端确认
					if(tcpHeader.getAcknowledgmentNumber()==localSequence){
						MLog.println("接收第三次握手 "+" ident "+ipV4Header.getIdentification());
						MLog.println(packet+"");
						Thread t1=new Thread(){
							public void run(){
								//startSend(basePacket_server,syc_sequence_client+1);
							}
						};
						//t1.start();
						connectReady=true;
					}
				}
				//MLog.println("客户端响应preview\n "+packet);
				//MLog.println("request "+tcp.ack());
				sendedTable_server.remove(tcpHeader.getAcknowledgmentNumber());
				boolean selfAck=selfAckTable.contains(ipV4Header.getIdentification());
				//MLog.println("客户端确认 "+"selfack "+selfAck+" id "+ipV4Header.getIdentification()+" ack_sequence "+tcpHeader.getAcknowledgmentNumberAsLong()+" "+sendedTable_server.size()+"ppppppp "+tcpHeader);
			}
			
		}else {
			if(tcpPacket.getPayload()!=null){
				preDataReady=true;
				onReceiveDataPacket( tcpPacket, tcpHeader, ipV4Header );
				byte[] sim=getSimResponeHead();
				sendData(sim);
			}
		}
	}else {
		if(tcpPacket.getPayload()!=null){
			onReceiveDataPacket( tcpPacket, tcpHeader, ipV4Header );
			TunData td=new TunData();
			td.tun=this;
			td.data=tcpPacket.getPayload().getRawData();
			capEnv.vDatagramSocket.onReceinveFromTun(td);
		}
	}
	if(tcpHeader.getRst()){
		MLog.println("reset packet "+ipV4Header.getIdentification()+" "+tcpHeader.getSequenceNumber()+" "+remoteAddress.getHostAddress()+":"+remotePort+"->"+localAddress.getHostAddress()+":"+localPort+" "+" ident "+ipV4Header.getIdentification());
	}

}