Java 中服务名称的端口?
我的服务文件(C:\ WINDOWS \ system32 \ drivers \ etc \ services)有一堆端口到服务的映射:
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以编程方式从端口转换为服务名称的方法(而不是解析)或第三方库?
伪代码:
Port port = new Port("443","tcp");
String service = port.getService();
System.out.println(service); //prints "https"
有什么好的方法可以实现这一点吗?
My services file (C:\WINDOWS\system32\drivers\etc\services) 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
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?
Pseudocode:
Port port = new Port("443","tcp");
String service = port.getService();
System.out.println(service); //prints "https"
Is there any good way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在寻找的是 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 forjava getservbyport
我认为java中没有用于此目的的API。
您需要解析此文件或以某种形式维护端口服务映射(属性文件、数据库等)。
从系统文件解析的示例是:
http://www.javafaq.nu/ java-example-code-162.html
I don't think there is some API in java for this purpose.
You will either need to parse this file or maintain port service mapping in some form (Properties file,db etc.).
example to parse from system file is :
http://www.javafaq.nu/java-example-code-162.html