15줄짜리 IP 알아내기 프로그램
글쓴이: segfault / 작성시간: 화, 2005/02/01 - 1:52오후
귀차니즘 버젼입니다... :)
하도 귀찮아서 그냥 popen으로.. 흐흐
#include <stdio.h>
int main(void)
{
FILE *fp;
char buffer[256], *p;
int i;
fp = popen("/sbin/ifconfig eth0", "r");
fgets(buffer, 255, fp);
fgets(buffer, 255, fp);
p = buffer+20;
for(i = 0; i < strlen(p); i++)
if(p[i] == ' ') { p[i] = '\0'; break; }
printf("%s\n", p);
fclose(fp);
}
KDE 사용자라면 kdialog -msgbox `myip` 이렇게 하면 GUI로도 뜹니다 :)
Forums:


[code:1]import httplibquery = "
import httplib query = "/" hostname = "checkip.dyndns.org" agent = "ifconfig" http = httplib.HTTP(hostname) http.putrequest("GET", query) http.putheader("User-Agent", agent) http.putheader("Host", hostname) http.putheader("Accept", "*/*") http.endheaders() errcode, errmsg, headers = http.getreply() file = http.getfile() print file.read()파이썬으로 만든 귀차니즘 버전입니다. HTML 코드 파싱은 귀찮아서 생략.
앗, 윗글은 제가 쓴 겁니다. 이런 건 이름을 남겨야 제 맛... -_-
앗, 윗글은 제가 쓴 겁니다. 이런 건 이름을 남겨야 제 맛... -_-;
아, 라인 수를 줄이는 게 목표인 것 같아서 다시 해봤습니다.[c
아, 라인 수를 줄이는 게 목표인 것 같아서 다시 해봤습니다.
import urllib print urllib.urlopen("http://checkip.dyndns.org").read()재미삼아서..[code:1]#!/bin/sh/sbin/if
재미삼아서..
첫번째 interface의 ip만 뽑아낸다면 대충[code:1]#
첫번째 interface의 ip만 뽑아낸다면 대충
#!/bin/sh /sbin/ifconfig | grep "inet" | awk '{print $2}' | sed 's/^.*://g' | head --lines=1hostname -i
hostname -i
python으로 다르게 하면 [code:1]import socket
python으로 다르게 하면
덧) hostname -i 하면 /etc/hosts 파일에 적힌대로 나오지 않나요?
....
[root@nalle ~]# ifconfig | grep "inet addr" | grep -v "127.0.0" | cut -d: -f2 | cut -d" " -f1
192.168.0.9
=== 건달의 경지를 꿈꾸며 ===
lynx -dump http://checkip.dyndns.org | g
lynx -dump http://checkip.dyndns.org | grep "IP Address"
----
I paint objects as I think them, not as I see them.
atie's minipage
:twisted: atie님 코드를 카피했습니다.[code:1]w3
:twisted: atie님 코드를 카피했습니다.
w3m -dump http://checkip.dyndns.org | grep "IP Address"----
아발발다빠따반반나다발딸발발다빠따따맣밤밤따받따발발다따밝다발발다빠따따밤반다빠따다맣밥발
발다따밥다발발다따박다발발다빠따따밞밭밭다따다맣아희
[quote="atie"]lynx -dump http://checkip.
lynx -dump http://checkip.dyndns.org |grep "IP Address" | awk {'print $4'}
댓글 달기