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.