import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class InetAddressInUse {
public static void main(String[] args){
try {
InetAddress ip4 = Inet4Address.getLocalHost();
System.out.println(ip4.getHostAddress());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
//补充
//获取本机ip地址
InetAddress addr = InetAddress.getLocalHost();
String ip=addr.getHostAddress().toString();
String iptest = request.getLocalAddr(); //ip:0:0:0:0:0:0:0:1
//补充
获得端口号:
int port = request.getLocalPort() //8080
前端获取端口
var hostname = location.hostname;
获取端口号
var port = location.port;
获取主机名+端口号
var host = location.host;
访问:localhost:8090/login.html
hostname = localhost;
port = 8090;
host = localhost:8090