Port to Service Name in Java?

后端 未结 2 1518
长情又很酷
长情又很酷 2020-12-19 08:16

My services file (C:\\WINDOWS\\system32\\drivers\\etc\\services) has a bunch of Port to Service mappings:

echo                7/tcp
echo                7/udp         


        
相关标签:
2条回答
  • 2020-12-19 08:43

    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

    0 讨论(0)
  • 2020-12-19 08:57

    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

    0 讨论(0)
提交回复
热议问题