package com.cloudwise.doop.pg.util;
import java.net.InetAddress;
import java.net.URL;
public class UrlParser {
public static void parseURL(String urlString) {
try {
URL url = new URL(urlString);
String host = url.getHost();
int port = url.getPort();
// 如果端口未明确指定,则使用默认端口 80
if (port == -1) {
port = 80;
}
// 将主机名转换为 IP 地址
// InetAddress address = InetAddress.getByName(host);
// String ip = address.getHostAddress();
String ip = host;
System.out.println("IP Address: " + ip);
System.out.println("Port: " + port);
} catch (Exception e) {
System.out.println("Error parsing URL: " + e.getMessage());
}
}
public static void main(String[] args) {
parseURL("http://10.0.1.11:8080/aaa");
}
}