#include #include #include #include #include #include int IPtoDec (char *ip); int main() { using namespace std; WSAData wData; if (WSAStartup(MAKEWORD(2,2), &wData) == SOCKET_ERROR) { cout << "Winsock init error\n"; cout << "\n\nPress any key to exit.\n"; getch((); return 1; } hostent *h = NULL; char hostname[80]; cout << "\n\n" << "########################################\n" << "# Host Name to Decimal Equivalent v1.0 #\n" << "# by: ThermoFish (JW) #\n" << "########################################\n"; cout << "Enter hostname: "; cin >> hostname; h = gethostbyname(hostname); if (h == NULL) { cout << "Could not resolve " << hostname << endl; cout << "\n\nPress any key to exit.\n"; getch(); return 1; } char *ip = inet_ntoa(*(reinterpret_cast(h->h_addr))); cout << "\nIP address :" << ip << endl; IPtoDec(ip); cout << "\nPress any key to exit.\n"; getch(); return 0; } // Function to convert from IP to decimal int IPtoDec (char *ip) { { using namespace std; char *cptr = strtok (ip, "."); int shift = 24; unsigned long acc = 0L; while (cptr != NULL) { acc += atol(cptr) << shift; shift -= 8; cptr = strtok (NULL, "."); } cout << "\nIP as Decimal: " << acc << endl; } return 0; }