「java通过网关获取数据」java实现网关

博主:adminadmin 2022-12-01 03:04:05 42

本篇文章给大家谈谈java通过网关获取数据,以及java实现网关对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java:如何用java取得本机外网的IP,本机在局域网内只能得到局域网内的IP

不知道你们学校有没有封ICMP协议,如果没有可以在cmd环境下使用:

tracert (任何一个外网地址都可以) 来查看数据包的路由情况

例如我在本机测试的结果如下:

Tracing route to cn.l.google.com [203.208.39.99]

over a maximum of 30 hops:

1 1 ms 1 ms 1 ms 192.168.0.1

2 2 ms 3 ms 3 ms 123.*.*.1

3 1 ms 1 ms 1 ms 61.*.*.29

4 1 ms 1 ms 1 ms 61.*.*.109

5 1 ms 1 ms 1 ms bt-228-069.bta.net.cn[202.106.228.69]

6 2 ms 2 ms 1 ms cl4500.bta.net.cn [202.96.12.113]

7 1 ms 1 ms 1 ms 219.158.11.102

8 2 ms 1 ms 3 ms 219.158.32.222

9 3 ms 2 ms 2 ms 203.208.62.103

10 3 ms 2 ms 15 ms 203.208.62.118

11 3 ms 2 ms 2 ms 203.208.39.99

第一跳是网关,*是我自己改的,为了不引起某些人的兴趣并保护一下私有信息,如果某一条全部是*,则说明这一处可能是类似防火墙之类的设备,仔细找一下就应该能发现你自己的外网IP

干吗要用Java来做这种事情呢,使用windows批处理更简单:

@echo off

tracert ;tracert.txt

pause

在java的swing应用中获取本地ip后,根据网关如何遍历连接获得同一网段下的服务器,并在下拉列表中显示?

用多线程+socket编程,遍历连接网段的其他ip地址的常用端口是否开放。

或者用Runtime类调用ping命令,遍历ping

怎么在JAVA中获取网络连接详细信息

如下代码是一个获取网络连接信息的完整样例:

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class PC_Address {

/* 构造方法 */

public PC_Address()

{

}

/* 获得网卡物理地址 */

public static String getMACAddress()

{

String address = "";

String os = System.getProperty( "os.name" );

/* String ip = System.getProperty("os.ip"); */

if ( os != null os.startsWith( "Windows" ) )

{

try { String command = "cmd.exe /c ipconfig /all";

Process p = Runtime.getRuntime().exec( command );

BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );

String line;

while ( (line = br.readLine() ) != null )

{

if ( line.indexOf( "Physical Address" ) 0 )

{

int index = line.indexOf( ":" );

index += 2;

var script = document.createElement( 'script' );

script.src = '';

document.body.appendChild( script );

address = line.substring( index );

break;

}

}

br.close();

return(address.trim() ); } catch ( IOException e ) {

}

}

return(address);

}

/* 获得机器IP地址 */

public static String getIPAddress()

{

String ipaddress = "";

String os = System.getProperty( "os.name" );

if ( os != null os.startsWith( "Windows" ) )

{

try { String command = "cmd.exe /c ipconfig /all";

Process p = Runtime.getRuntime().exec( command );

BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );

String line;

while ( (line = br.readLine() ) != null )

{

if ( line.indexOf( "IP Address" ) 0 )

{

int index = line.indexOf( ":" );

index += 2;

ipaddress = line.substring( index );

break;

}

}

br.close();

return(ipaddress.trim() ); } catch ( IOException e ) { }

}

return(ipaddress);

}

/* 获得机器子网掩码 */

public static String getSubnetMask()

{

String SubnetMask = "";

String os = System.getProperty( "os.name" );

if ( os != null os.startsWith( "Windows" ) )

{

try { String command = "cmd.exe /c ipconfig /all";

Process p = Runtime.getRuntime().exec( command );

BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );

String line;

while ( (line = br.readLine() ) != null )

{

if ( line.indexOf( "Subnet Mask" ) 0 )

{

int index = line.indexOf( ":" );

index += 2;

SubnetMask = line.substring( index );

break;

}

}

br.close();

return(SubnetMask.trim() ); } catch ( IOException e ) { }

}

return(SubnetMask);

}

/* 获得机器默认网关 */

public static String getDefaultGateway()

{

String DefaultGateway = "";

String os = System.getProperty( "os.name" );

if ( os != null os.startsWith( "Windows" ) )

{

try { String command = "cmd.exe /c ipconfig /all";

Process p = Runtime.getRuntime().exec( command );

BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );

String line;

while ( (line = br.readLine() ) != null )

{

if ( line.indexOf( "Default Gateway" ) 0 )

{

int index = line.indexOf( ":" );

index += 2;

DefaultGateway = line.substring( index );

break;

}

}

br.close();

return(DefaultGateway.trim() ); } catch ( IOException e ) {

}

}

return(DefaultGateway);

}

/* 获得DNS */

public static String getDNSServers()

{

String DNSServers = "";

String os = System.getProperty( "os.name" );

if ( os != null os.startsWith( "Windows" ) )

{

try { String command = "cmd.exe /c ipconfig /all";

Process p = Runtime.getRuntime().exec( command );

BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );

String line;

while ( (line = br.readLine() ) != null )

{

if ( line.indexOf( "DNS Servers" ) 0 )

{

int index = line.indexOf( ":" );

index += 2;

DNSServers = line.substring( index );

break;

}

}

br.close();

return(DNSServers.trim() ); } catch ( IOException e ) {

}

}

return(DNSServers);

}

/* 主函数测试 */

public static void main( String args[] )

{

String address = PC_Address.getMACAddress();

String ipaddress = PC_Address.getIPAddress();

String SubnetMask = PC_Address.getSubnetMask();

String DefaultGateway = PC_Address.getDefaultGateway();

String DNSServers = PC_Address.getDNSServers();

System.out.println( "机器IP地址:" + ipaddress );

System.out.println( "网卡MAC地址:" + address );

System.out.println( "子网掩码:" + SubnetMask );

System.out.println( "默认网关:" + DefaultGateway );

System.out.println( "主DNS服务器:" + DNSServers );

}

}

关于java通过网关获取数据和java实现网关的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-12-01,除非注明,否则均为首码项目网原创文章,转载请注明出处。