The IPAddress class contains methods to access the local IP address, gateway IP address and subnet mask.
IPAddress.localIP()Gets the WiFi shield's IP address
IPAddress.localIP();
none
the IP address of the shield
#include <WiFi.h>
char ssid[] = "yourNetwork"; //SSID of your network
int status = WL_IDLE_STATUS; // the Wifi radio's status
IPAddress ip; // the IP address of your shield
void setup()
{
// initialize serial:
Serial.begin(9600);
WiFi.begin(ssid);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true);
}
// if you are connected, print out info about the connection:
else {
//print the local IP address
ip = WiFi.localIP();
Serial.println(ip);
}
}
void loop () {}
IPAddress.subnetMask()Gets the WiFi shield's subnet mask
IPAddress.subnet();
none
the subnet mask of the shield
#include <WiFi.h>
int status = WL_IDLE_STATUS; // the Wifi radio's status
//SSID of your network
char ssid[] = "yourNetwork";
//password of your WPA Network
char pass[] = "secretPassword";
IPAddress ip;
IPAddress subnet;
IPAddress gateway;
void setup()
{
WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true);
}
// if you are connected, print out info about the connection:
else {
// print your subnet mask:
subnet = WiFi.subnetMask();
Serial.print("NETMASK: ");
Serial.println(subnet);
}
}
void loop () {
}
IPAddress.gatewayIP()Gets the WiFi shield's gateway IP address.
IPAddress.gatewayIP();
none
An array containing the shield's gateway IP address
#include <SPI.h>
#include <WiFi.h>
int status = WL_IDLE_STATUS; // the Wifi radio's status
//SSID of your network
char ssid[] = "yourNetwork";
//password of your WPA Network
char pass[] = "secretPassword";
IPAddress gateway;
void setup()
{
Serial.begin(9600);
WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true);
}
// if you are connected, print out info about the connection:
else {
// print your gateway address:
gateway = WiFi.gatewayIP();
Serial.print("GATEWAY: ");
Serial.println(gateway);
}
}
void loop () {}