IPAddress()

描述

定义 IP 位址。可以用来描述本机或远端的位址。

语法


IPAddress(address);

参数

位址:一串以逗号分隔的数字用以代表位址(4 个位元组,如: 192, 168, 1, 1)

回传

无回传值

范例

#include <Ethernet.h>

// 网路设定。DNS 伺服器、通讯闸和子网路遮罩可选择给或不给

byte mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };  

// DNS 伺服器的 IP 位址
IPAddress dnServer(192, 168, 0, 1);
// 路由器的通讯闸位址
IPAddress gateway(192, 168, 0, 1);
// 子网路遮罩
IPAddress subnet(255, 255, 255, 0);

// 你的电脑 IP 位址
IPAddress ip(192, 168, 0, 2);

void setup() {
  Serial.begin(9600);

  // 初始化网路装置
  Ethernet.begin(mac, ip, dnServer, gateway, subnet);
  // 印出 IP 位址
  Serial.print("IP = ");
  Serial.println(Ethernet.localIP());
}

void loop() {
}

函式库参考主页面

The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.