IP : Java Glossary



Briefly How IPs work

Let’s say you and your roommate browse YouTube. You each are working on your own computer, both attached to a LAN (Local Area Network), possibly WiFi (Wireless Fidelity), attached to the Internet. There are a number of IPs at play. IPs are roughly like Internet phone numbers. Assume your computer has a local IP of Your roommate might have a local IP Your computer talks to the router via the router’s local IP probably The router then talks to your IAP (Internet Access Provider) via the router’s face IP something like

When you, or your roommate, visits YouTube, YouTube knows both of you by the common face IP YouTube has no idea what your local IPs are. YouTube can however, tell you apart by which port it dynamically assigns to you for your conversations.

Usually a protocol called DHCP (Dynamic Host Configuration Protocol) assigns all the IP numbers and keeps them the same for days or weeks at a time.

IP (Internet Protocol). The lowest level protocol of the Internet upon which everything else is based. It simply sends packets, with no checks that they arrived and no retransmission. Built on top of this are the UDP (User Datagram Protocol) and TCP/IP (Transmission Control Protocol/Internet Protocol) protocols. Java does not give application programs access to the IP level, just TCP/IP Sockets and Datagrams and protocols built on top of them. Every machine on the Internet has a unique 32-bit address called its IP. Parts of the Internet have converted to 128-bit addresses called IPv6 IPv6 (Internet Protocol Version 6).

Note that IPv6 addresses are 128 bits, 16 bytes, 4 times longer than IPv4 (Internet Protocol Version 4) addresses. You’d think 64 bits, allowing 18,744,073,709,551,616 addresses, or 30,77,457 addresses per person would have sufficed. However, to avoid another transition for a very long time, they went for 128 bits. This will allow simpler routing, since bands can be assigned for various regions that won’t soon fill up and require juggling to shift slots from other regions.

A standard IPv4 is written as a dotted quad e.g. , four numbers 0..255. When entering these numbers into windows configuration dialogs, you will find it most convenient if you don’t key the dots and zero-pad each group to three digits, e.g. 065 110 020 044. In programming, sometimes a dotted quad such as is written as a giant 32-bit unsigned decimal number e.g. [1090214183] or in hex [40FB5927]. For example can get at my website by DNS (Domain Name Service) name or by IP number with the following URL (Uniform Resource Locator) s: http://mindprod.com or http://

IPv6 does not work well. You can get Java to prefer IPv4 with -Djava.net.preferIPv4Stack=true

IP Owner IP bit manipulation
IP From Domain Name IPv6
Domain Owner IP Assignment
Domain/IP Location IP Protocol
Face IP Learning More
Your Own IP Books
Others’ IP Links
Displaying an IP


There are five common questions about domain names and IP you may have:

  1. Who owns this IP?
  2. I know the domain name. What IP does it map so I can put an entry in my hosts. file.
  3. Who owns this domain name?
  4. Where on the planet is this IP broadcasting from?
  5. What is my face IP?
  6. Is this server available/up?

1. Who Owns This IP?

For the first question, who owns or is currently using this IP, see IP lookup services

2. Finding the IP From a Domain Name

For the second question, finding the IP given the domain name, you need an DNS lookup service:

3. Finding out who owns a Domain

For the third question (who owns this domain) use one of these whois services:

You might think it sufficient for to check if a domain name is taken to simply point your browser to www.xxxxx.com and see if you get a 404 not found error. However, the name may be taken, with no webserver set up, so the name would appear to be free when it was actually taken.

4. Finding out Where a Domain/IP is Located

For third question (where is the domain located) use one of these IP locator services:

5. Finding our Your Face IP

Ways of Finding Your Face IP
Logo Link Notes
moose Your face IP :[] Your face IP is displayed at the bottom of every page of this website. I do this with SSI (Server Side Includes).
IPChicken logo IPchicken.com tells your face ip and which ports you have open. They also tell you your face name, e.g. your URL on the web, possibly temporarily assigned for your connection. It might look something like this S0106991195576dda.gv.shawcable.net or d207-81-138-97.bchsia.telus.net That is not my real one. I don’t want to encourage hackers.
Dyn logo checkip.dyndns.org:8245/ Offers many other services as well.
WhatIsMyIPAddress logo WhatIsMyIPAddress.com has many annoying ads you must close to discover the answer.
In a Servlet you can use javax.servlet. ServletRequest. getRemotePort().
The face ip is different from the IP of your computer on the LAN. An IP of a computer on a LAN is typically something like The router has two ips, one it talks to the computers on the lan often and one it uses to talk to the outside world, dynamically assigned by the ISP using DHCP.

6. Is this server available/up?

Available Applet is a whoIs that tells you if a server is available/up. It also tells you the IP given the host or the host given the IP.

WhatIsMyIP has a number of IP tools for programmers.

Available Applet  is a whoIs that tells you if a server is available/up. It also tells you the IP given the host or the host given the IP.

WhatIsMyIP has a number of IP tools for programmers.

Determining your own IP Address

In Java you can determine the IP of the machine running the Java application or Applet with: Unfortunately, unsigned Applets will be told the hostname is localhost/ since such nosiness is considered a security breach. Signed Applets will be told the truth. Further, if you are behind a router or firewall, you will just get your local LAN address, e.g. [], not the facing address you are known by out on the Internet via your proxy.

In JSP (Java Server Pages), the following methods may be useful: request.getServerName(), request.getServerPort() and request.getRequestURI()

If you are writing an Applet, you can find out the name of the server indirectly via Applet.getCodeBase. You have to use the URL.getHost method to pull out just the part you want.

If your webserver supports SSI you can get such information via the REMOTE_HOST ( URL ) REMOTE_ADDR ( IP ) SERVER_NAME (URL ) and SERVER_ADDR ( IP ) directives.

In Windows, you can use the utility ipconfig /all to display information such as IP, subnet mask, DNS Server IP, host name, physical ethernet 48-bit MAC (Media Access Control) address, gateway IP and DHCP server IP. In older versions of Windows there is a similar utility called winipconfig. You can spawn this utility from Java with the exec function and programmatically scan through the output to find what you need. Alternatively, you need to write platform specific JNI (Java Native Interface) code to grab additional information, such as DNS servers, gateways, masks, etc.

Your router will divulge all kinds of information. Read your manual how to talk to it. How you do it is model-dependent. With mine I must use my browser to go to then logon with a userid and password.

On Windows IpConfig.exe will tell you quite a bit.

Wireshark will also tell you the IP-v6 of each interface as it refers to the various Ethernet connections.

There are various utilities that periodically probe to find out your IP address, then notify you if your face IP changes and also notify the DynDns server.

Finding Out Someone Else’s IP

You can convert DNS name to IP or IP to DNS name with this snippet of Java code. In other words, you can find out the DNS name or IP of an arbitrary website given either its name or IP with: You can use Obviously you must be online to the Internet for these calls to work and you need a functioning DNS lookup) server. I have heard reports that if either of these conditions are not met, instead of getting an exception, you just get as the IP of every website.

If you are behind a firewall you may not have access to DNS or reverse DNS lookup. You might experiment by putting the DNS-IP pair in your Windows or NT HOSTS file, or working purely with IPs. Sometimes the receiver requires a DNS name, not just a pure IP. In that case you can provide one with URLConnection.setRequestProperty().

I know of no way to discover your DNS server IP without resorting to JNI.

Unfortunately, finding out your server’s IP will trip the sandbox security mechanism in an Applet. You could sign the Applet, or you can dance around the problem this way: you get the server name from getCodeBase().getServer(), open a Socket to port 80 and retrieve the local IP address from that Socket. If getServer() returns null, the Applet is running locally and you could just use localhost namely as the IP address. In Linux you could use .

You can find out who owns a domain name at http://www.networksolutions.com/whois/index.jsp. Unfortunately, you can no longer find out who owns an IP. For that you need arin.net.

If you need finer control than InetAddress gives you, e.g. the ability to select the DNS server, try DNSJava.

To find out your own IP address you could lookup localhost using InetAddress. getByName but that would just give you which is not likely what you really wanted. In Windows, you can spawn ipconfig.exe /renew and capture the IP Address line in the output.

Java maintains a cache for DNS lookup. You can control its behaviour with:

Displaying an IP

IP bit manipulation tricks


The new IP standard is IPv6. It uses 128-bit address. When presented to humans, these 16-byte IP are written in hex in 8 groups of 4 hex digits like this 1080:0:0:0:8:800:200C:41FA. Lead zeros on a group may be left off.

How Are IP ’s Assigned

Websites have a permanently assigned IP. IANA (Internet Assigned Numbers Authority) manages assigning them through sort of wholesale distributor system. For dialup, PPP temporarily assigns you an IP that stays constant until you hang up. For workstations with permanent connections, DHCP automatically assigns you a temporary IP number using a discoverable IP number server. With the explosive growth of the Internet, we are running out of IP numbers and will at some point have to go IPv6 protocol with more address bits.

For computers not directly attached to the Internet, (e.g. via a proxy server), or on a LAN that has Internet access, but without individual station access, or on an isolated LAN, you don’t need universally unique IP numbers. You can use the ones reserved for local private LAN use. You don’t need to get anyone’s permission to use them such as ..

IP Addresses
IP Range Format
A large (null) .. ..
(any private LAN) .. (localhost)

1 bit 
7 bits
Local address
24 bits
B medium .. ..
(any private LAN) ..

2 bits
14 bits
Local address
16 bits
C small .. ..
(any private LAN) ..

3 bits
21 bits
Local address
8 bits

Usually a router on a home LAN is and DHCP will assign computers on the LAN to addresses in the range and you assign any static IP on the LAN in the range

The scheme above turned out to be too limiting, so now it is largely ignored, IP are assigned as bands of consecutive integers on any boundary. This more flexible system is called CIDR (Classless Inter-Domain Routing). Because we are running out of IP we have quadrupled their size to 128 bits with IPv6. That oughta hold ’em, 3 followed by 38 zeros of IP to choose from.

One of the rather terrifying things about the way the Internet is designed is that there is little to stop people from configuring their machines with IP they have no business using. It becomes trivially easy to steal unused or rarely used IP s, to spoof someone else’s identity, or to spy on someone else’s traffic. The Internet protocols were not designed to deal with malicious teenage hackers, only gentlemanly academics.

woodpecker If builders built buildings the way programmers write programs, then the first woodpecker that came along would destroy civilization.
~ Weinberg’s Second Law (born:1933-10-27 age:83)

How the IP Protocol Works

The IP protocol is the most primitive and basic protocol of the Internet. Everything else — datagrams, TCP/IP sockets, Telnet, FTP (File Transfer Protocol), HTTP… is built-in layers on top. IP protocol deals with deliverying one fairly small packet, end-to-end over a number of hops. The delivery is not guaranteed. IP protocol makes no provision for retransmitting garbled or lost packets. IP is similar to UDP protocol, except that UDP can deliver bigger payloads that a split over several physical packets.

The IP protocol can best be understood by looking at the header that goes on each packet. The IP packet header is a bit like the baggage tag you attach to your suitcase before entrusting it to the airline:

IPv4 Packet Header
Field Size in bits Purpose
version 4 4 for IP version 4. This allows IPv4 and IPv6 packets to be mixed.
hlen 4 size of packet header measured in 32-bit chunks.
total length 16 total size of packet header plus data payload measured in 8-bit chunks (aka bytes or octets). The means the maximum size of a packet including data is 64K. This means the payload of data is at most 65,515 bytes.
time to live 8 how many more hops/seconds this packet has to live before being discarded as lost or hopelessly late. On each leg of this packet’s journey, this field gets decremented by 1 or the number of seconds of delay at that hop if the delay was greater than one second.
header checksum 16 digest of just the header to ensure the header has not been scambled in transmission. It has to be recomputed at each hop to account for the new value of the time to live field. Note that the body of the packet is not protected by checksum. That has to be done at a higher level, e.g. UDP or TCP/IP.
source IP 32 Who sent the packet. When it finally arrives at its destination the receiver will know who it was from.
destination IP 32 Where the packet is going. On each leg of its journey the routing computer uses this to get the packet a little closer to its final destination.
other stuff 48 Miscellaneous fields.

Everything is in big endian byte order.

The sender tosses his packet of data into the Internet, with the header. Computers on the net pass the packet along hoping to get it closer and closer to its destination. Perhaps a dozen hops later it finally arrives. Perhaps it doesn’t. There is nothing in IP protocol to guarantee safe arrival. However, if a packet has to be split up for part of its journey, IP will automatically reassemble the parts.

IP protocol does not sound too promising. Unlikely you will use IP protocol directly. UDP ( via Java classes DatagramPacket and DatagramSocket) and TCP/IP (via Java classes Socket and ServerSocket) protocols are built on top of IP and FTP and HTTP (Hypertext Transfer Protocol) (via Java class HttpURLConnection) are built on top of TCP/IP.

Learning More

Oracle’s Javadoc on InetAddress class : available:
Oracle’s Javadoc on Inet4Address class : available:
Oracle’s Javadoc on Inet6Address class : available:


book cover recommend book⇒Internetworking with TCP/IP Vol.1: Principles, Protocols and Architecture, fourth editionto book home
by Douglas E. Comer 978-0-13-470188-2 paperback
publisher Prentice Hall 978-0-13-018380-4 hardcover
published 2000-01-18
How IP, UDP and TCP/IP protocols work. How the domain name to IP translation DNS information in propagated.
Australian flag abe books anz abe books.ca Canadian flag
German flag abe books.de amazon.ca Canadian flag
German flag amazon.de Chapters Indigo Canadian flag
Spanish flag amazon.es Chapters Indigo eBooks Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Nook at Barnes & Noble American flag
Italian flag amazon.it Kobo American flag
India flag junglee.com Google play American flag
UK flag abe books.co.uk O’Reilly Safari American flag
UK flag amazon.co.uk Powells American flag
UN flag other stores
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
hide the ip
domain names
Dyn: three free services of interest to people who host webservers on their home machines
face IP
Internet troubleshooting
MaxMind of IP to geographical location: database you buy
MaxMind service to get geographical location of an IP: free service
Networking Properties
QuickDNS download
QuickDNS manual
RFC 791 defines the IP protocol
RFC 815 describes how datagrams are reassembled
subnet mask

This page is posted
on the web at:


Optional Replicator mirror
of mindprod.com
on local hard disk J:

Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

Your face IP:[]
You are visitor number