(solved) I want to print IP-address on webpage (Ethernet Shield)

When you use

#include <SPI.h>
#include <Ethernet.h>
byte ip[] = { 192, 168, 14, 85};

in your sketch for a web page. How do I get the byte ip shown in the web page?


is not the right way, but I can’t figure out what is should be

Have you tried something like this:


Not sure what you are trying to do. Do you want an arduino web server to include the IP address in the returned web page?

Do you want an arduino web server to include the IP address in the returned web page?

Yep that's what I'm trying to do. When you visit the webpage on the arduino, it should show in html the IP-address of the Arduino webserver (ethernet Shield)

The webpage I'm working on will be a setup-page where you can change the IP address of you Ethernet Shield, but for now I want to know how you can show the actual IP.


You may want to look at the DHCP code at the below site to see how info is obtained from a router.


Ok, Understand your code (I think :roll_eyes:)

But, what I simply want to do is, print the IP-address the arduino webservers has, on the webpage, or a 16x2 LCD screen, or de serial console.

May be too simple, but couldn't you also set the ip address as a string variable in the setup part of the code if you have already set it as the ip address to use?

Yes true, but how? can't I just print the IP have set in byte ip[] = { 192, 168, 14, 85}; ?

No, you cant display: byte ip[] = { 192, 168, 14, 85} out of the box. This is an array of 4 bytes. To make them human readable, you have to translate them to characters.

The Serial.print() function knows how to translate most simple variables to characters, i.e. byte, int, float, char, etc.

The most simple solution - already mentioned - is to store the IP address 2 times, one time as a byte array for the code and one time as a char array (i.e. string) for humans.

Another way is to write a function which translates the byte array to a string.

PaulS has shown you even another way.

Have you tried using itoa()??

char[4] printIP;

itoa((int)ip[0], printIP, 10); Serial.print(printIP); Serial.print("."); //rinse repeat

YES victory. thanks bubulindo (just had to change

char[4] printIP;

into char printIP[4];

This sketch shows a webpage with the webservers IP-address showing.

#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 
  192, 168, 14, 85};
char printIP[4]; 
Server server(80);
void setup()
  Ethernet.begin(mac, ip);
void loop()
  Client client = server.available();
  if (client) {
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (c == 'n' && current_line_is_blank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          itoa((int)ip[0], printIP, 10);
          itoa((int)ip[1], printIP, 10);
          itoa((int)ip[2], printIP, 10);
          itoa((int)ip[3], printIP, 10);
        if (c == 'n') {
          current_line_is_blank = true;
        else if (c != 'r') {
          current_line_is_blank = false;

Java is destroying my poor knowledge of C. I’m sorry. LOL

There’s an example on the Networking section of the forum, showing how to print the IP address:

for (int n = 0; n<=3; n++)

The thread is this one:

Give it a try and see which is smaller. :slight_smile:

The above doesn't seem to work, it shows numbers, but not the ip address. Your other solution does work. :)

Now I'm trying to show the MAC-address, but

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

gives me


which is not hexadecimal, but decimal. I know this is basic stuff, but it's late. Good night :sleeping:

use itoa(mac[0], string_mac, 16);
but you need to add the 0x to the string before you print to the screen.

I haven’t got my arduino here with me, but it worked for me at home. :S

It worked as you can see in this topic:


Thanks bubulindo