getting the last IP octet

Ok I've looked everywhere for this and cant find any info.

I have an arduino with an ethernet shield and am using the standard ethernet library, I am trying to populate an integer with the last octet of the IP and just dont know here to start, any help would be greatly appreciated

Cheers

Mike

The IPAddress variable can be accessed like an array.

IPAddress ip = Ethernet.localIP();
Serial.println(ip[3]);

OMG it was that simple?

I feel like a right tard now :blush:

but thank you :slight_smile:

Mike

mikeoxlarge:
OMG it was that simple?

I feel like a right tard now :blush:

Don't feel bad. The documentation doesn't cover stuff like this very well. I know this only by examples and the header/cpp files.

I feel like a right tard now

Well, you shouldn't. There was no reason for the Arduino team to borrow a page from Microslop, and obfuscate what used to be quite simple. A mac address or an IP address is a collection of values - an array. There is no reason to use typedefs to give the arrays fancy names that do nothing useful.

Hmmmmm, that seems to throw the network adapter in to a fit, sorry guys but am having a really stupid day today, lets say I have the following

int startnum = 0;

How would I get startnum to = the last octet, there's a packet of bourbon biscuits in this for the answer (you pay shipping though) lolol

cheers

Mike

What do you meany by "throws the network adapter in a fit"?

IPAddress ip = Ethernet.localIP();
byte startnum = ip[3];

If this doesn't do it, post your code.

That did the trick, I'm basically getting three boxes to broadcast every five minutes just the last octet of their ip address, thi is then stored in a table in an application in the pc but also does some other functions in the arduino that needed it as an integer, and it's now working :slight_smile:

Thank you so much :slight_smile:

Am off to the shop now to buy a packet of bourbon cremes :slight_smile: