地味にめんどくさげ。Tango 0.99.7 と DMD 1.033 による。
import tango.net.Socket, tango.net.InternetAddress; import tango.io.Buffer; import tango.net.http.HttpHeaders, tango.net.http.HttpConst, tango.net.http.HttpGet; import tango.io.Stdout; void main(){ auto udp = new Socket(AddressFamily.INET, SocketType.DGRAM, ProtocolType.UDP); udp.bind(new InternetAddress(1024)); // 俺用の適当なポート番号 udp.sendTo("M-SEARCH * HTTP/1.1\r\n" "MX: 3\r\n" "HOST: 239.255.255.250:1900\r\n" "MAN: \"ssdp:discover\"\r\n" "ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n\r\n", new InternetAddress("239.255.255.250", 1900)); char[1024] response; auto len = udp.receiveFrom(response); auto headerBuf = new Buffer(cast(char[])response[0..len]); auto hhv = new HttpHeadersView; hhv.parse(headerBuf); auto xml = cast(char[])(new HttpGet(hhv.get((new HttpHeader).Location))).read; Stdout(xml)(); }