Skip to content

Instantly share code, notes, and snippets.

@y109
y109 / DNSLookup.cpp
Last active May 13, 2016 19:48 — forked from AyoubOuarrak/DNSLookup.cpp
dns lookup
// Author : Ouarrak Ayoub
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <iostream>
#include <netdb.h>
#include <cstring>
#include <string>
@y109
y109 / int2ip.cpp
Created May 13, 2016 19:26 — forked from rikioy/int2ip.cpp
int2ip
string int2ip(unsigned int ip_num){
struct in_addr in;
in.s_addr = ip_num;
return inet_ntoa(in);
}
@y109
y109 / get_ip_from_nic.c
Created May 13, 2016 19:24 — forked from libesz/get_ip_from_nic.c
Sample C code to obtain the IP address attached to a selected network interface under Linux.
/*
* Sample C code to obtain the IP address attached to
* a selected network interface under Linux.
*
* Found here: http://www.geekpage.jp/en/programming/linux-network/get-ipaddr.php
*
* Missing includes added.
*/
#include <stdio.h>
@y109
y109 / inet_ntoa.c
Created May 13, 2016 19:19 — forked from bg1bgst333/inet_ntoa.c
inet_ntoa#inet_ntoa.c
/* ヘッダファイルのインクルード */
#include <stdio.h> /* 標準入出力 */
#include <sys/types.h> /* 派生型 */
#include <sys/socket.h> /* ソケット */
#include <netinet/in.h> /* AF_INET, AF_INET6アドレス・ファミリー */
#include <arpa/inet.h> /* IPアドレス変換 */
/* main関数の定義 */
int main(void){
@y109
y109 / testdns.c
Created May 13, 2016 19:17 — forked from jiphex/testdns.c
Barebones dig using inet_ntoa in C
#include <netdb.h>
#include <stdio.h>
int main(int argc, char * argv[]) {
if(argc > 1) {
int i;
struct hostent *hent;
hent = gethostbyname(argv[1]);
printf("Hostname: %s\n", hent->h_name);
for(i = 0; hent->h_addr_list[i] != 0; i+=1) {
printf("IP: %s\n", inet_ntoa(*((long *)hent->h_addr_list[i])), i);