Best way to create IPEndpoint from string

This is one solution… public static IPEndPoint CreateIPEndPoint(string endPoint) { string[] ep = endPoint.Split(‘:’); if(ep.Length != 2) throw new FormatException(“Invalid endpoint format”); IPAddress ip; if(!IPAddress.TryParse(ep[0], out ip)) { throw new FormatException(“Invalid ip-adress”); } int port; if(!int.TryParse(ep[1], NumberStyles.None, NumberFormatInfo.CurrentInfo, out port)) { throw new FormatException(“Invalid port”); } return new IPEndPoint(ip, port); } Edit: Added a version … Read more

How to get ip address from sock structure in c?

OK assuming you are using IPV4 then do the following: struct sockaddr_in* pV4Addr = (struct sockaddr_in*)&client_addr; struct in_addr ipAddr = pV4Addr->sin_addr; If you then want the ip address as a string then do the following: char str[INET_ADDRSTRLEN]; inet_ntop( AF_INET, &ipAddr, str, INET_ADDRSTRLEN ); IPV6 is pretty easy as well … struct sockaddr_in6* pV6Addr = (struct … Read more

What is the most appropriate data type for storing an IP address in SQL server? [duplicate]

Storing an IPv4 address as a binary(4) is truest to what it represents, and allows for easy subnet mask-style querying. However, it requires conversion in and out if you are actually after a text representation. In that case, you may prefer a string format. A little-used SQL Server function that might help if you are … Read more

How do I determine all of my IP addresses when I have multiple NICs?

Use the netifaces module. Because networking is complex, using netifaces can be a little tricky, but here’s how to do what you want: >>> import netifaces >>> netifaces.interfaces() [‘lo’, ‘eth0’] >>> netifaces.ifaddresses(‘eth0’) {17: [{‘broadcast’: ‘ff:ff:ff:ff:ff:ff’, ‘addr’: ’00:11:2f:32:63:45′}], 2: [{‘broadcast’: ‘10.0.0.255’, ‘netmask’: ‘255.255.255.0’, ‘addr’: ‘10.0.0.2’}], 10: [{‘netmask’: ‘ffff:ffff:ffff:ffff::’, ‘addr’: ‘fe80::211:2fff:fe32:6345%eth0’}]} >>> for interface in netifaces.interfaces(): … … Read more