开发者

Socket that listens for everything

开发者 https://www.devze.com 2023-04-06 04:48 出处:网络
I have a computer on my network that had multiple IP addresses and uses multiple ports. Is there any way to open a socket that receives data on all those ip addresses and all those ports, and then hav

I have a computer on my network that had multiple IP addresses and uses multiple ports. Is there any way to open a socket that receives data on all those ip addresses and all those ports, and then have the data received contain the ip address from the packet heade开发者_开发百科r, and the port it received it on?

Rephrase: How can I set up a socket that can receive data on multiple ports and IPs? Then once I receive the data, is there any way to know where the data came from?


You cannot bind to multiple ports using just one socket. The TCP/IP networking stack is based on the idea that one port == one socket.


To listen on all IP adresses just use INADDR_ANY. However you will still need one socket per port.


var s = array();
for(i = 1; i <= 65535; i++) {
    s[i] = socket.listen_port(i);
    fwrite('file.dat', s[i].read()."\n");
}

Ofcourse in your programing language. Thats idea only. Dont forget, that if port already used by another application, you wont be able to read or write to it - i think so...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号