So if I have an IP address IP Address:, is it somehow possible to change a specific byte of that IP to like IP Address: 192.64.**6**.1

My idea is to change the IP Address into variables IP Address: a.b.c.d Now I could say a= 192; b= 64; c= 5 + 1; d= 1

But what if I receive the IP Address: as a String. Is it somehow possible to split it up into 4 parts that I can each individually assign to an integer (a, b, c or d)?


You can do it all with the IPAddress class.

For instance: create an IP address from a string:

IPAddress myAddr(myString);

Create a new IP address with one byte changed:

IPAddress myNewAddr(myAddr[0], myAddr[1], myAddr[2] + 1, myAddr[3]);
  • and myAddr[2] = 6. myAddr[2]+=1 or myAddr[2]++ works too – Juraj Feb 6 '19 at 18:11

Yes, you can split the string with the C library function strtok, than concatenate everything together with your own string with the C library strcat. You can convert strings to atoi, so use the resulting string from strtok with atoi to an integer.

Tip: try it on a PC with a local C compiler, because you can check it very fast (unless you can implement it first time right). Than you copy it to your Arduino sketch. Make sure to start with a char buffer big enough for the biggest possible IP address string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.