Tag: hostname

DNS, Information Gathering

Resolve hostname to ip without using ping

To resolve a hostname to its IP address without using Ping (ICMP echo request), you can use dig or nslookup. You should avoid using ping because ICMP requests may alert administrators when an IDS/IPS system is installed at the target system or even worse ICMP echo requests are blocked from a firewall.   dig hostnamedig …

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, Ubuntu

Change the hostname or computer name in linux

1. Open a terminal window. 2. Type the following command and hit Enter: sudo gedit /etc/hostnamesudo gedit /etc/hostname 3. Replace the current computer name with the desired new name and save. 4. Type the following command: sudo gedit /etc/hostssudo gedit /etc/hosts 5. Change the old 127.0.1.1 line to your new hostname. 6. Reboot

Python

Hostname, Internal and External IP address in Python

Let’s see the code: import socket print "Hostname:", socket.gethostname() print "Internal IP:", socket.gethostbyname(socket.gethostname())   s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("google.com", 80)) print "External IP:", s.getsockname()[0] s.close()import socket print "Hostname:", socket.gethostname() print "Internal IP:", socket.gethostbyname(socket.gethostname()) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("google.com", 80)) print "External IP:", s.getsockname()[0] s.close()