说明
获取Ethernet shield的IP地址。当通过 DHCP 自动分配地址时很有用。
用法
Ethernet.localIP();
参数
空
返回
- IP 地址
示例
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// print your local IP address:
Serial.println(Ethernet.localIP());
}
void loop() {
}
相关用法
- Arduino Ethernet - Ethernet.linkStatus()用法及代码示例
- Arduino Ethernet - Ethernet.setRetransmissionTimeout()用法及代码示例
- Arduino Ethernet - Ethernet.MACAddress()用法及代码示例
- Arduino Ethernet - Ethernet.hardwareStatus()用法及代码示例
- Arduino Ethernet - Ethernet.setDnsServerIP()用法及代码示例
- Arduino Ethernet - Ethernet.init()用法及代码示例
- Arduino Ethernet - Ethernet.setMACAddress()用法及代码示例
- Arduino Ethernet - Ethernet.setSubnetMask()用法及代码示例
- Arduino Ethernet - Ethernet.dnsServerIP()用法及代码示例
- Arduino Ethernet - Ethernet.setLocalIP()用法及代码示例
- Arduino Ethernet - Ethernet.gatewayIP()用法及代码示例
- Arduino Ethernet - Ethernet.setGatewayIP()用法及代码示例
- Arduino Ethernet - Ethernet.setRetransmissionCount()用法及代码示例
- Arduino Ethernet - Ethernet.begin()用法及代码示例
- Arduino Ethernet - Ethernet.subnetMask()用法及代码示例
- Arduino Ethernet - EthernetUDP.parsePacket()用法及代码示例
- Arduino Ethernet - EthernetUDP.beginPacket()用法及代码示例
- Arduino Ethernet - EthernetUDP.available()用法及代码示例
- Arduino Ethernet - EthernetUDP.read()用法及代码示例
- Arduino Ethernet - EthernetUDP.endPacket()用法及代码示例
- Arduino Ethernet - EthernetUDP.begin()用法及代码示例
- Arduino Ethernet - EthernetServer()用法及代码示例
- Arduino Ethernet - EthernetClient()用法及代码示例
- Arduino Ethernet - EthernetUDP.write()用法及代码示例
- Arduino Ethernet - server.begin()用法及代码示例
注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 Ethernet - Ethernet.localIP()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。