Java: convert int to InetAddress

后端 未结 10 1184
既然无缘
既然无缘 2020-12-14 06:34

I have an int which contains an IP address in network byte order, which I would like to convert to an InetAddress object. I see that there is an <

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 07:34

    If you're using Google's Guava libraries, InetAddresses.fromInteger does exactly what you want. Api docs are here

    If you'd rather write your own conversion function, you can do something like what @aalmeida suggests, except be sure to put the bytes in the right order (most significant byte first).

提交回复
热议问题