How do I print my IP address?
Topic last updated
02 Jul 2012, by
frank van hooft.
4 replies
Dumb newbie question. How do I print my mbed's IP address?
If I do something along these lines:
struct IpAddr myip;
....
myip = eth.getIp();
pc.printf("Interface is up, local IP is %s\n", inet_ntoa(myip));
I get compiler errors about the unknown function inet_ntoa.
What's the easiest way of printing out the mbed's IP address?
Thanks.
Replies
Take a look at the HTTP server example on the Cookbook.
It shows in there how to print IP
Couldn't find anything in the cookbook I must admit. Although there was a mention that the IP addr is printed out the console.
Anyway, I discovered that putting this:
- include "inet.h"
allowed the inet_ntoa() function to work, which was perfect.
yeah the IP is printed to console there is a getip() function
IpAddr ethIp = eth.getIp();
printf("Connected ok, IP : %d.%d.%d.%d\n", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
const char* hwAddr = eth.getHwAddr();
printf("HW address : %02x:%02x:%02x:%02x:%02x:%02x\n",
hwAddr[0], hwAddr[1], hwAddr[2],
hwAddr[3], hwAddr[4], hwAddr[5]);
How do I print my mbed's IP address?
You can also use the getIPAddress method:
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
printf("IP Address is %s\n", eth.getIPAddress());
See the Ethernet Interface documentation.
Cheers,
Emilio
Please log in to post a reply.
Dumb newbie question. How do I print my mbed's IP address?
If I do something along these lines:
struct IpAddr myip;
....
myip = eth.getIp(); pc.printf("Interface is up, local IP is %s\n", inet_ntoa(myip));
I get compiler errors about the unknown function inet_ntoa.
What's the easiest way of printing out the mbed's IP address?
Thanks.