Tag: ip

C, Microsoft Windows, Network

Resolve hostname to ip address in C

Resolve hostname to ip address (TCP v4) in Windows using C and gethostbyname. #include <stdio.h> #include <winsock2.h> #include <ws2tcpip.h>   #pragma comment (lib, "Ws2_32.lib")   void resolve_hostname_to_ipaddress(char* hostname);   int main(int argc, char* argv[]) { resolve_hostname_to_ipaddress("hostname.com");   return EXIT_SUCCESS; }   void resolve_hostname_to_ipaddress(char* hostname) { struct hostent *he; struct in_addr **addr_list; int i;   WSADATA …

C, Microsoft Windows, Network

Resolve hostname to ip address in C

Resolve hostname to ip address (TCP v4) in Windows using C and getaddrinfo. #include <stdio.h> #include <winsock2.h> #include <ws2tcpip.h>   #pragma comment (lib, "Ws2_32.lib")   void resolve_hostname_to_ipaddress(char* hostname);   int main(int argc, char* argv[]) { resolve_hostname_to_ipaddress("hostname.com");   return EXIT_SUCCESS; }   void resolve_hostname_to_ipaddress(char* hostname) { DWORD ppi = -1; struct addrinfo hints; struct addrinfo *ptr …

Linux, Monitor, Network

Monitoring Opened TCP/IP network ports/connections in Linux

tcptrack displays the status of TCP connections that it sees on a given network interface. tcptrack monitors their state and displays information such as state, source/destination addresses and bandwidth usage in a sorted, updated list very much like the top command. The filter expression is a standard pcap filter expression (identical to the expressions used …

Monitor, Network

Monitoring Opened TCP/IP network ports / connections

CurrPorts is network monitoring software that displays the list of all currently opened TCP/IP and UDP ports on your local computer. For each port in the list, information about the process that opened the port is also displayed, including the process name, full path of the process, version information of the process (product name, file …

C#

Get public/external IP address

Use the following code to get your wan/external/public ip address using http://dyndns.org site. try { System.Net.WebClient wc = new System.Net.WebClient(); String s = wc.DownloadString("http://checkip.dyndns.org"); s = ( new System.Text.RegularExpressions.Regex( @"bd{1,3}.d{1,3}.d{1,3}.d{1,3}b")). Match(s).Value; wc.Dispose(); Console.WriteLine(s); } catch (Exception) { //… }try { System.Net.WebClient wc = new System.Net.WebClient(); String s = wc.DownloadString("http://checkip.dyndns.org"); s = ( new System.Text.RegularExpressions.Regex( @"bd{1,3}.d{1,3}.d{1,3}.d{1,3}b")). …

Linux

List network interfaces

Type the following command: ip link showip link show Output 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether c7:0b:a4:e3:81:02 brd ff:ff:ff:ff:ff:ff 3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 00:11:b2:23:64:55 brd ff:ff:ff:ff:ff:ff1: lo: <LOOPBACK,UP,LOWER_UP> …