Good day all
I am going through the MSDN website try to familiarize mystelf with Multicasting and how it works. I'm wondering: when does one use the
IPAddress.Any
it refers to a commented out line from this link
//IPAddress localIP = IPAddress.Any;
I have seen it on multiple occasions, but what does IPAddress.Any really mean?
UPDATE
A quick googling reveals:
What's IPAddress.Any - MSDN Forums:
IPAddress.Any will listen on any IP Addresses assigned to the PC. For
example, if I am connected to the network via wireless and wired,
there would be two IP Addresses assigned. This means that I would
listen for requests on both IP Addresses. If I would take the IP of
say the wired then I could only receive requests from that NIC.
As you can see, this is for specifying an address to listen on (effectively, an equivalent to IPAddress.Parse("0.0.0.0")) and thus is not specific to multicasting. See How to do a UDP multicast across the local network in c#? for an example of the latter's implementation.
Related
Building a bit of code that does auto configuration of IP addresses, when they start they all have the same IP, this software uses multicast to find the other devices on the network and uses that information to figure it's own IP configuration.
However if they have the same IP they stop receiving multicast packets, but if I force them to have different IPs multicast starts working again. Is multicast tied to IP address or can multiple devices with the same IP receive multicast.
We cannot use APIPA/Link-Local addressing.
Thanks,
Dan
Multicast does not mean broadcast. Multicast means to send data only to devices which have previously requested this multicast group.
You cannot use multicast to reach any previously unconfigured machines. For this you have to, use broadcast (i.e. 255.255.255.255).
Multicast relies on the IGMP protocol, which in turn relies on a working IP unicast setup, which in turn requires that all devices can be uniquely identified by their IP addresses. IGMP messages contain the unicast IP address of the sending device.
In your setup all the nifty optimization algorithms in all the network components along the path (routers, switches, also the devices themselves) will fail since they cannot identify the targets which request the multicast group. They may fail in any random way. It is completely undefined how multiple devices with the same IP address behave.
In your case some network component decides that there is no need to distribute the multicast packets to the involved ports, as there is no unique receiver connected to the port. (I am just speculating here. Any other answer will be correct, too. Just an example to explain how this could behave the way you see it.)
I'm working on a socket project and now I'll make a UDP listener for server-side. I have looked some examples and I can't understand this; Why we have to bind UDP socket like "socket.Bind(new IPEndPoint(IPAddress.Any, 3000));"? Namely: in the TCP socket, we bind only our local ip but in UDP socket, we are binding IPAddress.Any. Why we are doing this?
EDIT: What are the wildcard and particular IP Adresses? How can we use them?
I found this and I think I was looking for it :)
The wildcard is a special local IP address. It usually means "any" and
can only be used for bind operations.
The value of this IP address is 0.0.0.0. If you have two network
adapters, one with IP address 1.1.1.1 and one with IP address 2.2.2.2,
then you can create a listening socket and bind it to 1.1.1.1 so that
the socket will not bind to 2.2.2.2. You can also create a listening
socket and bind it to 2.2.2.2, so that it will not bind to 1.1.1.1. If
you do not care and want your socket to bind to all network cards,
then you bind it to the wildcard address.
Another special value would be 127.0.0.1, meaning that only clients on
the same computer could connect to your server.
Link: What does wildcard address in InetSocketAddress mean?
You can bind both TCP and UDP sockets to either the wildcard address (INADDR_ANY or IN6ADDR_ANY_INIT) or to a specific address. There is no reason why you would typically bind a TCP socket to a specific IP address while you would bind a UDP socket to a wildcard address.
Is it true that, if I want to make an IP spoofing program, I need only a program that can change my machine IP address?
If true how can I use System.Net - IPAddress Class to set the ip address?
No, it is not true. Changing your machine's IP address is not IP spoofing. IP spoofing is when you create network packets that have a source IP address that does not match the actual IP address of the source machine.
http://en.wikipedia.org/wiki/IP_address_spoofing
This could be achieved using RAW sockets or WinPCap using SharpPCap to interop to WinPCap
http://www.tamirgal.com/blog/page/SharpPcap.aspx
Your machine IP address is simply the IP address given to your machine to be used internally by devices within your home network. This is how routers, switches and other client devices can deliver and exchange packets.
You cannot spoof your external-facing IP in this manner. Using proxies will make the proxy's IP appear to be your external-facing IP.
I do not suggest changing your internal IP unless you know what you are doing and actually have a need for it to be static. For example, I forward ports on my router so I can run services. The router knows to point that traffic directly to my internal IP. Because DHCP can change your IP (due to lease expiration and what not), it's best that I make my internal IP static.
Also, depending on your network configuration, your internal IP has a certain format, like 192.168.1.X.
The best way to http://www.change-ip-proxy.com>change your ip address is through a proxy. In my search for a proxy, I found that having a reliable company behind the proxy is very important. Everything you do is sent through the company’s proxy, so you want to be sure that you can trust them to not read or steal your personal information. Or else there's no point in having a proxy.
I have a socket application which I can use in local network, at home.
I can make them communicate for example from 192.168.x.x to 192.168.y.y ip addresses.
What should I do if I want to use the application over internet, from a remote machine, not local. For example which ip addresses should I use if my friend who lives another country wants to access my application.
On the server end, the easiest way is to bind to all available addresses by using IPAddress.Any as the address. You'll need to give the client your public Internet address to connect to. If you're being a NAT, it might involve looking at your router for the address (or using http://www.whatismyip.com/) and configuring it to route the traffic to your PC.
You need to set up your router to forward the port that you wish to communicate on. Once you have that in place, give your friend your public IP address.
For instance, you can configure your router rules to point all port 80 requests to your 192.168.x.x machine, so that when ever a request for port 80 comes in, it automatically gets sent to a specific address on your subnet.
Your outgoing IP address. Use this site to see it: http://www.whatismyip.com/
And of cause port forward your router.
You will have to use the IP address provided by you ISP (internet service provider). Usually these IP addresses are non static, so that you need to provide some way to resolve your dynamic IP address to a static name (dyndns providers do this usually).
In addition you need to configure you router to forward the incomming traffic on port xxx to your local machine (this is usually not your router, except when you are using a modem). This is called port forwarding.
We have a simple piece of legacy software with which we need to
communicate using TCP/IP over port 15001. We need to listen on port 15001
for the legacy software to make a connection and then read whatever it sends us.
We have tested this solution accross the internet and it works just fine.
If however we test the same solution across a GPRS TCP/IP network it does not.
All the basics have been checked, we can ping other devices in the GPRS network
and port 15001 is not blocked by any firewall.
So maybe there is something wrong with my TcpListener?
It is initialized like this:
tcpServer = new TcpListener(IPAddress.Any, TCP_PORT);
I'm assuming it listens on every available IPv4 enabled interface on the system,
because I used IPAddress.Any ?
Does anybody have any idea what the difference might be between the two networks? (Even though there shouldn't be any difference) and if there is something I need to change to my TcpListener?
You need to specify the IP address on which you want to listen, instead of IPAddress.Any. See here. When you use IPAddress.Any, it will automatically choose the network interface for you. To listen on a certain interface (in your case, GPRS) you have to use the correct IP in the constructor.
This post has more information on getting the IP address for each nic.
Also, if you're looking to listen on every IP address at once, you'll need a TcpListener for each nic.