• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

help with InetAddress.getByAddress() ?

 
Ranch Hand
Posts: 193
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an ip address, but need the hostname. To clarify, this is not the ip address of my localhost. I was thinking InetAddress.getByAddress(byte[] b) would do the trick. But several octets in the ip are greater than 127. For instance, 112.217.200.12 (I made that up). I am thinking the people who designed this class would known this would be the case and have thought of a solution. Does anyone know how to get around the byte value limit? Thank you.
 
Ranch Hand
Posts: 245
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works same way as reading/writing from/to files using byte arrays. This method uses byte as unsigned.

112.217.200.12 will be this array:

2 middle elements will be negative but that is OK.

Or can use InetAddress.getByName which accepts IP address, too:
 
Higgledy Smith
Ranch Hand
Posts: 193
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Vlado Zajac. I would not have known getByName would take the ip as a string --the api does not saying anything about it. Thanks again.
 
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic