Java中服务名称的端口? [英] Port to Service Name in Java?
问题描述
我的服务文件(C:WINDOWSsystem32driversetcservices)有一堆端口到服务的映射:
My services file (C:WINDOWSsystem32driversetcservices) has a bunch of Port to Service mappings:
echo 7/tcp
echo 7/udp
discard 9/tcp sink null
discard 9/udp sink null
systat 11/tcp users #Active users
systat 11/udp users #Active users
daytime 13/tcp
daytime 13/udp
qotd 17/tcp quote #Quote of the day
qotd 17/udp quote #Quote of the day
chargen 19/tcp ttytst source #Character generator
我想找到一种方法,通过 Java API(而不是解析)或第三方库以编程方式从端口转换为服务名称?
I am trying to find a way to convert from a Port to the Service Name programmatically through Java APIs (instead of parsing) or third party libraries?
伪代码:
Port port = new Port("443","tcp");
String service = port.getService();
System.out.println(service); //prints "https"
有什么好的方法可以做到这一点吗?
Is there any good way to accomplish this?
推荐答案
您正在寻找的是 Linux getservbyport()
系统调用的 Java 实现.看看 http://github.com/wmeissner/jnr-netdb.另外,在 Google 上搜索 java getservbyport
What you are looking for is a Java implementation of the Linux getservbyport()
system call. Take a look at http://github.com/wmeissner/jnr-netdb. Also, do a Google search for java getservbyport
这篇关于Java中服务名称的端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!