I have a server with 4 ip addresses and four clients that each register their ip address with a service. Each client runs the same ruby script that connects via a TCP socket to the service.
The problem I have is all four scripts are connecting via the same IP address so three are receiving authorisation errors because they have the wrong ip address.
Is it possible to tell the TCP client to use a specific ip address?
Related
I'm interested in differentiating connections coming from the same PC.
socket.request.connection.remoteAddress; works perfectly for me on 1.0.4 to give me the public IP, but it will run into trouble when people are behind routers
For public ip - Get the client's IP address in socket.io
You have to use a combination of remote IP and remote Port to differentiate connections. If multiple connections come from behind the same router, your server would see them having the same public IP from the router, but they would be using different ports.
Although most of the hosts have ipv6 address now, there are still some hosts that only have ipv4. In my LAN, connections using ipv4 will cost money, while connections using ipv6 is free. I want to implement a proxy to convert ipv4 and ipv6 request, so that I can connect to ipv4 host free.
Is it possible to implement that? And is there any available software?
This largely depends on the devices, services/protocols and the direction you want to connect in.
NAT64/DNS64
With NAT64/DNS64 you can let IPv6-only clients connect to IPv4-only servers. The system looks up the name of the server it wants to connect to using the DNS64 server. If the DNS64 server sees that only an IPv4 address is available it will replace the IPv4 address of the server with a special IPv6 address in which it has encoded the original IPv4 address. When the IPv6-only system connects to that IPv6 address the NAT64 router knows that the intention is to connect to the IPv4 address encoded in the IPv6 address and it will set up a NAT session to that IPv4 address. The NAT64 box needs to have both an IPv4 and IPv6 address to be able to do this.
HTTP Proxy
If you only want to support HTTP and similar protocols then you might be able to use an HTTP proxy server. It will need to have both an IPv4 and IPv6 address, and your applications/devices need to support using a proxy server. It will work both for IPv4-only clients and IPv6-only servers and vice-versa.
SOCKS5
A SOCKS5 proxy server can also be used in the same way that an HTTP proxy server can be used, but with a wider variety of protocols. Your clients need to support it though.
Other
There are other more application-specific ways to proxy between IPv4 and IPv6. The few mentioned above are just to give you an idea of common ones.
When starting H2 tcp server and the host pc has multiple IP address's how can I define the IP that the server is going to bind to listen for connections ?
We can define the tcp port but there does not seems to be a way to define the ip address.
Thank you, Oscar
http://www.h2database.com/html/advanced.html#server_bind_address
Usually server sockets accept connections on any/all local addresses.
This may be a problem on multi-homed hosts. To bind only to one
address, use the system property h2.bindAddress. This setting is used
for both regular server sockets and for SSL server sockets. IPv4 and
IPv6 address formats are supported.
Imagine a Windows box, which:
hosts a WCF service
has multiple NICs
sits behind NAT
When a user issues a request to the service (on top of the WCF infrastructure), he uses the external address assigned to the target machine by the NAT.
I have to write some piece of code inside the WCF service, which must know which of the several NICs that the machine has was used to actually handle the network traffic. How does this code identify the NIC is less important - it could be its MAC address (the best) or it could be the (internal) IP address of the NIC.
How can I do it?
EDIT1
I will try to supply the question context. There are two agents. Both expose the same WCF service. In addition, one of the agents can be instructed to start probing the network towards the second agent in the following fashion:
Agent A is asked to probe the network to agent B
Agent A negotiates with agent B the UDP port to utilize for the sake of probing using the WCF service exposed by the agent B.
Once negotiation is over, the agent A starts some custom protocol over UDP, where the agent B acts as the server - i.e. it binds to the UDP port negotiated in the previous item.
Binding to a UDP port requires two pieces - the IP address and UDP port, where the IP address can either be a specific IP address or * (to bind to all the IP addresses associated with the machine). The latter option is not good for us - I will omit the reasons. This leaves us the former option - binding to the specific IP address. However, when the agent B is behind NAT, the IP address used to talk to the WCF service is the external IP address assigned to the agent by the NAT. Binding, on the other hand, requires the respective internal IP address - how to get it?
Can you check the OperationContext.Current.Channel.LocalAddress (it's an EndpointAddress) inside a WCF operation?
As a side note, getting the remote address can be done with:
OperationContext context = OperationContext.Current;
MessageProperties prop = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpoint =
prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
string ip = endpoint.Address;
--larsw
To get the MAC use
System.Net.NetworkInformation.NetworkInterface.GetPhysicalAddress();
All Nics:
System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
to find out what is the real listening ip address you can write a code that listen to your port on each address and ping it from an agent emulator to see that the address is valid.
Cheers,
Gilad
I am developing an P2P application where a peers talk to the server to inform its Private and Public IP. The application uses UDP for communication.
To get the private IP the client uses gethostbyname and bind it to that IP. The problem is when the system has more than one NIC. The problem is when one of the NIC is not connected to internet. So to avoid it i am using INADDR_ANY and bind it.
Now i need to get my local IP address to inform to the server. Is there any API which will tell me which IP address of the NIC is active?
You need to bind to an explicit IP address rather than INADDR_ANY as binding to INADDR_ANY will mean that calling getsockname() on the socket to get the local address will simply return INADDR_ANY.
So, what you need to do is iterate the available endpoints (using getaddrinfo()) and create a socket on each. These will then give you the correct address if you call getsockname() on them later.