java thread

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;

import java.io.*;

public class PrintUDisk extends JSch implements TestInterface, Runnable {
 int size = 1000;
 PrintUDisk(){
 size=33;
 }
 public int getFreeSize() {
 return size;
 }

 public Session getSession() throws JSchException {
 Session s = super.getSession(USER,HOST,PORT);
 s.setConfig("StrictHostKeyChecking","no");
 s.setPassword(PASS);
 return s;
 }

 public String uptime() throws JSchException, IOException {
 Session s = this.getSession();
 s.connect(3000);
 Channel c = s.openChannel("shell");
 PipedInputStream pipIn = new PipedInputStream();
 PipedOutputStream pipOut = new PipedOutputStream(pipIn);
 FileOutputStream fileOut = new FileOutputStream( file, true);

 c.setInputStream(pipIn);
 c.setOutputStream(fileOut);

// c.setInputStream(System.in);
// c.setInputStream(new FilterInputStream(System.in) {
// public int read(byte[] b, int off, int len) throws IOException {
// return in.read(b, off, (len > 1024 ? 1024 : len));
// }
// });
 c.connect();
 pipOut.write("sudo su\n".getBytes());
 pipOut.write("uptime\n".getBytes());
 pipOut.write("exit\n".getBytes());
 c.disconnect();
 s.disconnect();
 return "done";
 }

 @Override
 public void name() {

 }

 @Override
 public void type() {

 }

 @Override
 public void run() {
 while (size>0) {
 System.out.println(Thread.currentThread().getName() + ": " + size);
try {
Process exec = Runtime.getRuntime().exec("ping www.163.com");
InputStream ret = exec.getInputStream();
System.out.println(new String(ret.readAllBytes(),"GB2312")); 
size--;
 } catch (IOException e) { e.printStackTrace();}
 }
}
import com.jcraft.jsch.JSch;
import java.util.ArrayList;

public class TestObject {
    JSch jsch;
    public static void main(String[] args) {
        String s[] = {"a","z"};
        System.out.println(s[1]);
        PrintUDisk pu = new PrintUDisk();
        Thread th = new Thread(pu,"th");
        Thread th1 = new Thread(pu,"th1");
        th.start();
        th1.start();
    }
}

iscsi client and server setup

targetcli
/> backstores/fileio create test /tmp/test.img 100m
/> iscsi/ create iqn.2006-04.com.example:test-target
/> cd iscsi/iqn.2006-04.com.example:test-target/tpg1/
tpg1/> luns/ create /backstores/fileio/test
tpg1/> set attribute generate_node_acls=1
tpg1/> exit

systemctl enable target.service

 

 

Springboot run os command

package com.example.demo;

import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Collectors;

@Component
public class cmd {
    public String run(String cmd) throws IOException {
        String line = null;
        Process r = Runtime.getRuntime().exec(cmd);
        InputStreamReader in = new InputStreamReader(r.getInputStream());
        BufferedReader br = new BufferedReader(in);
        return br.lines().collect(Collectors.joining("</br>"));
    }
}

Springboot Scheduling

package com.example.demo;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@EnableScheduling
@RestController
public class login {
    @RequestMapping("/login")
    public String login(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String,String> map) throws IOException {

        cmd c = new cmd();
        return c.run(map.get("u"));
    }

    @RequestMapping("/redo")
    @Scheduled(cron = "0 */1 *  * * * ")
    public String redo() {
        System.out.println(String.format(String.format("a " + new Date()) ));
        return String.format(String.format("a " + new Date()) );
    }

    @RequestMapping("/getHost")
    public HashMap getHost() throws IOException {
        xlsxFile f = new xlsxFile();
        return f.Sheet();
    }

    @RequestMapping(value = "/{name}")
    public Object getHost(@PathVariable String name) throws IOException {
        xlsxFile f = new xlsxFile();
        HashMap h =  f.Sheet();
        return h.get((Object) name);
    }

}

java excel

package com.example.demo;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.stereotype.Component;
import org.xml.sax.XMLReader;

import javax.print.attribute.standard.DateTimeAtCompleted;
import java.io.*;
import java.util.HashMap;
import java.util.Iterator;

@Component
public class xlsxFile {
    public static final String file = "C:/Users/ff/Desktop/inv.xlsx"    ;

    public static void main(String[] arags) throws IOException, OpenXML4JException, FileNotFoundException {
        Workbook wb = WorkbookFactory.create(new File(file));
        DataFormatter dataFormatter = new DataFormatter();
        wb.forEach(sheet -> {
            if(sheet.getSheetName().contains("VM")) {
                try {
                    content(sheet,dataFormatter);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
            }
            });
    }

    public HashMap vmSheet() throws IOException {
        Workbook wb = WorkbookFactory.create(new File(file));
        DataFormatter dataFormatter = new DataFormatter();
        Sheet sheet = wb.getSheetAt(1);
        return showContent(sheet,dataFormatter);
    }

    public HashMap showContent(Sheet sheet, DataFormatter df) throws FileNotFoundException {
        HashMap hm = new HashMap<String, String>();
        int lastRow = sheet.getLastRowNum();
        Iterator<Row> rowIterator = sheet.iterator();
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            String key = null;
            String value = null;
            Iterator<Cell> cell = row.cellIterator();
            while (cell.hasNext()) {
                Cell c = cell.next();
                int columnIndex = c.getColumnIndex();
                if (columnIndex == 0) {
                    key = c.getStringCellValue();
                }
                if (columnIndex == 2) {
                    value = c.getStringCellValue();
                }
                if (key != null & value != null) {
                    hm.put(key, value);
                }
            }
        }
        return hm;
    }

    public static void content(Sheet sheet,DataFormatter dt) throws FileNotFoundException {
        host h = new host();
        System.setOut(new PrintStream(new FileOutputStream("C:/Users/ff/Desktop/inv.txt")));
        sheet.forEach(row -> {
            row.forEach(
                    cell -> {
                        String cellValue = dt.formatCellValue(cell);
                        if ((cell.getColumnIndex() ==  0 || cell.getColumnIndex() ==  2 )  && cell.getRowIndex() > 0 && cellValue.length() !=0 ) {
                            System.out.printf("%-20s",cellValue);
                        }
                    });
            System.out.println();
        });
    }
}

Ubuntu 16.04 remote capture by Wireshark

Linux SIDE
wget http://www.winpcap.org/install/bin/WpcapSrc_4_1_2.zip
 unzip WpcapSrc_4_1_2.zip 
cd winpcap/wpcap/libpcap/
 chmod +x configure runlex.sh 
apt install libpcap-dev  flex
 ./configure 
make
cd rpcapd/
make
rpcapd [-b <address>] [-p <port>] [-6] [-l <host_list>] [-a <host,port>]
 [-n] [-v] [-d] [-s <file>] [-f <file>]
 -b <address>: the address to bind to (either numeric or literal).
 Default: it binds to all local IPv4 addresses
 -p <port>: the port to bind to. Default: it binds to port 2002
 -4: use only IPv4 (default both IPv4 and IPv6 waiting sockets are used)
 -l <host_list>: a file that keeps the list of the hosts which are allowed
 to connect to this server (if more than one, list them one per line).
 We suggest to use literal names (instead of numeric ones) in order to
 avoid problems with different address families
 -n: permit NULL authentication (usually used with '-l')
 -a <host,port>: run in active mode when connecting to 'host' on port 'port'
 In case 'port' is omitted, the default port (2003) is used
 -v: run in active mode only (default: if '-a' is specified, it accepts
 passive connections as well
 -d: run in daemon mode (UNIX only) or as a service (Win32 only)
 Warning (Win32): this switch is provided automatically when the service
 is started from the control panel
 -s <file>: save the current configuration to file
 -f <file>: load the current configuration from file; all the switches
 specified from the command line are ignored
 -h: print this help screen

Win SIDE:
Wireshark -> Remote Interfaces -> +
Host: x.x.x.x Port: 2002