首页 > 编程知识 正文

内网穿透python,java获取用户ip

时间:2023-05-03 14:34:56 阅读:16506 作者:2924

私有静态获取工具(

字符串tempip=' 127.0.0.1 '; try { if (isip v4 (inet地址. get localhost ().getHostAddress ) ) )

tempip=inet address.get localhost ().getHostAddress );

}catch(unknownhostexceptionE1) {//todo auto-generated catch块

E1 .打印堆栈跟踪(;

}try{

enumeration networks=network interface.getnetworkinterfaces (;

inet地址IP=null;

枚举地址; while(NetWorks.hasmoreelements ) ) )

{

addrs=networks.nextElement ().getInetAddresses ); while(addrs.hasmoreelements ) )

{

ip=addrs.nextElement (; if(IP!=空值

ipinstanceofinet 4地址IP.issitelocaladdress! ip.getHostAddress ().equals () tempip ) )

{if(isipV4(IP.gethostaddress () ) ) returnip.getHostAddress );

}

}

}returntempIP;

}catch(exceptione ) {

System.out.println; thrownewruntimeexception(e;

}

} publicstaticbooleanisipv4(字符串IP地址) {

stringip=' ^ (1 d {2}|2 [0-4]d|25 [0-5]|[1-9]d|[1-9] () ) () () ) )

' (00? d|1d {2}|2 [0-4]d|25 [0-5]|[1-9]d|\ d ]\\."

' (00? d|1d {2}|2 [0-4]d|25 [0-5]|[1-9]d|\ d ]\\."

' (00? d|1d {2}|2 [0-4]d|25 [0-5]|[1-9]d|\d ] $ ';

pattern pattern=pattern.com pile (IP;

matcher matcher=pattern.matcher (IP地址); returnmatcher.matches (;

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。