Get the IP port assigned by ngrok


One sentence description of ngrok
: Free, I don’t know if it restricts traffic for the time being. The
main is to penetrate the intranet and map the port you specify to the Internet to access the

client download address
https:/ /ngrok.com/download

supports Window Linux Arm MacOS

proxy region by default US, optional Asia, Europe, etc. For

example , I set up two modes of web and ssh, respectively http address https address, ssh tcp port
Because free users, give All are random numbers (temporarily replaced by xxxx), the second column is the exit IP address of your client, the third column is the area where the service is called, I chose Singapore (ap, this distance is better than us)
quote

http://xxxxx.ap.ngrok.io 111.164.xx.xx ap
https://xxxx.ap.ngrok.io 111.164.xx.xx ap
tcp://0.tcp.ap.ngrok.io:xxxx 111.164.xx.xx ap


The principle is that the client creates a long connection with the server that provides services remotely, and ngrok will open the interface for external access. When there is an http or tcp request, it will forward the corresponding request to your client and return the result (such as visiting a website) ) This method can easily debug programs that require Internet applications (such as WeChat services)

because there are already many online tutorials. The following is just to log in to the website through java, obtain the currently automatically assigned domain name and port information through the username and password, and output the results. As shown above,

depending on the jar file
, jsoup is mainly used to parse html, and Ali's fastjson is used to parse the json result

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.jsoup.Connection;
import org.jsoup.Connection.Method;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class JoupPost {	
	/**
	 * https website login and get the ip address in the json information inside
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		//The website login element has username, password, and hidden token
		Map<String,String> map = new HashMap<String, String>();
		map.put("email", "[email protected]");
		map.put("password", "xxxx");
		//1 get token
		Connection con1 = Jsoup.connect("https://dashboard.ngrok.com/user/login");
		Response rs1 = con1.execute();
		Map<String,String> cookies = rs1.cookies();
		Document doc1 = rs1.parse();
		Elements es1 = doc1.getElementsByAttributeValue("name","csrf_token");
		if(!es1.isEmpty()){
			map.put("csrf_token",es1.get(0).attr("value"));
//			System.out.println(es1.get(0).attr("value"));
		}
		
		//Log in to the website through token and cookie
		Connection con2 = Jsoup.connect("https://dashboard.ngrok.com/user/login");
		con2.referrer("https://dashboard.ngrok.com/user/login");
		con2.cookies(cookies);
		con2.timeout(60*1000);
		con2.data(map);
		con2.method(Method.POST);
		Response rs2 = con2.execute();
		cookies = rs2.cookies();
//		System.out.println("cookie2:"+cookies);
//		Document doc2 = rs2.parse();
//		System.out.println(doc2.body());
		
		//Call the status query page to get web page data
		Connection con3 = Jsoup.connect("https://dashboard.ngrok.com/status");
		con3.referrer("https://dashboard.ngrok.com/status");
		con3.cookies(cookies);
		con3.timeout(30*1000);
		Document doc3 = con3.get();
//		System.out.println(doc3.body());
		
		//Get the div tag, then get the json data in the tag, and then parse the json
		Element e = doc3.getElementById("preloaded");
		JSONObject jo = JSONObject.parseObject(e.attr("data-value"));
		JSONArray ja = jo.getJSONArray("online_tunnels");
//		System.out.println(ja.toJSONString());
		
		for(Object j:ja){
			JSONObject o = (JSONObject)j;
			System.out.println(o.getString("url")+"\t "+o.getString("remote_addr")+"\t "+o.getString("region"));
		}
	}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326291139&siteId=291194637