我的networking服务器上有一个虚拟主机,唯一的目标是返回客户端的IP地址:
petrus@bzn:~$ cat /home/vhosts/domain.org/index.php <?php echo $_SERVER['REMOTE_ADDR']; echo "\n" ?>
这有助于我解决networking问题,尤其是涉及到NAT的时候。 因此,我并不总是有域名parsing,即使通过IP地址查询,这个服务也需要工作。
我这样使用它:
petrus@hive:~$ echo "GET /" | nc 88.191.133.41 80 191.51.4.55 petrus@hive:~$ echo "GET /" | nc ydct.org 80 191.51.4.55 router#more http://88.191.133.41/index.php 88.191.124.254
但是,我发现至less有一台电脑没有工作:
petrus@seth:~$ echo "GET /" | nc ydct.org 80 petrus@seth:~$ petrus@seth:~$ echo "GET /" | nc 88.191.133.41 80 petrus@seth:~$
我检查了什么:
这与ipv6无关:
petrus@seth:~$ echo "GET /" | nc -4 ydct.org 80 petrus@seth:~$ petrus@hive:~$ echo "GET /" | nc ydct.org 80 2a01:e35:ee8c:180:21c:77ff:fe30:9e36
netcat版本是相同的(除平台,i386与x64):
petrus@seth:~$ type nc nc est haché (/bin/nc) petrus@seth:~$ file /bin/nc /bin/nc: symbolic link to `/etc/alternatives/nc' petrus@seth:~$ ls -l /etc/alternatives/nc lrwxrwxrwx 1 root root 15 2010-06-26 14:01 /etc/alternatives/nc -> /bin/nc.openbsd petrus@hive:~$ type nc nc est haché (/bin/nc) petrus@hive:~$ file /bin/nc /bin/nc: symbolic link to `/etc/alternatives/nc' petrus@hive:~$ ls -l /etc/alternatives/nc lrwxrwxrwx 1 root root 15 2011-05-26 01:23 /etc/alternatives/nc -> /bin/nc.openbsd
它在没有pipe道的情况下使用:
petrus@seth:~$ nc ydct.org 80 GET / 2a01:e35:ee8c:180:221:85ff:fe96:e485
pipe道至less有一个testing服务( netcat监听1234 / tcp并输出到stdout)
petrus@bzn:~$ nc -l -p 1234 GET / petrus@bzn:~$ petrus@seth:~$ echo "GET /" | nc ydct.org 1234 petrus@seth:~$
我不知道这个问题是否与netcat或Apache更相关,但我很感激任何指针来解决这个问题!
bzn是服务器,hive是一个工作的客户端,seth是我有问题的客户端。
编辑:它也适用于telnet但telnet不允许pipe道。
第二次编辑回答MickeyB:
实际上,主机头文件不会被传输,但正如上面的hive主机所见,我已经将Apache的default虚拟主机configuration为像ydct.org vhost:
petrus@bzn:/etc/apache2/sites-available$ cat default <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName 88.191.133.41 ServerAlias 2a01:e1b:1:132:1a0a:a9ff:fec8:f0a9 DocumentRoot /home/vhosts/ydct.org/ </VirtualHost>
但是,它适用于curl !
petrus@seth:~$ curl ydct.org 2a01:e35:ee8c:180:221:85ff:fe96:e485
apache2 -S输出发布到http://pastebin.com/aSf446Jv
但我想知道为什么它不适用于netcat …
总之,它正在运行的netcat版本。
我testing了我的机器上的命令string,如下所示:
Mac OS X Lion:
yvaine:sqlite user$ echo -e "GET /" | nc 88.191.133.41 80 XX.XX.XX.168
FreeBSD的:
[root@freebsd82 /usr/ports]# echo -e "GET /" | nc 88.191.133.41 80 XX.XX.XX.168
CentOS的:
[root@kvm0001 ~]# echo -e "GET /" | nc 88.191.133.41 80 XX.XX.XX.168
Debian(版本6)
root@debian:~# echo -e "GET /" | nc 88.191.133.41 80 XX.XX.XX.168
直到我到了Ubuntu“清醒”(这是你显然正在运行)是当我得到这个:
root@ubuntu:~# echo -e "GET /" | nc 88.191.133.41 80 root@ubuntu:~#
看来,Ubuntu默认为nc.openbsd,而不是nc.traditional(这是Debian的默认设置)。 一旦我使用传统的版本,我收到了所需的输出:
root@ubuntu:~# echo -e "GET /" | nc.traditional 88.191.133.41 80 XX.XX.XX.168
好奇的是你的两台客户机都有nc.openbsd,但是它们的行为却不一样。 当然,也可能是其中一个版本是nc.openbsd,或者是不同版本的Ubuntu。 在这两者中,你可以同步你的版本nc.openbsd或切换到nc.traditional。
适用于我:)
michael@challenger:~$ echo -e "GET /\n" | nc 88.191.124.41 80 <html><body><h1>It works!</h1> <p>This is the default web page for this server.</p> <p>The web server software is running but no content has been added, yet.</p> </body></html>
如果你正在尝试击中虚拟主机,那么你的操作不正确。 您需要发送主机:标题来标识您要使用的虚拟主机。
使用“什么是我的IP”服务的最佳方式是curl。 嘿,看,当我做你正在做的事时,我看到了同样的问题:
michael@challenger:~$ echo -e "GET /" | nc ip.mydomain.ca 80 michael@challenger:~$ curl ip.mydomain.ca 192.168.0.135
修复你的怪物!
michael@challenger:~$ curl -v 88.191.124.41 * About to connect() to 88.191.124.41 port 80 (#0) * Trying 88.191.124.41... connected * Connected to 88.191.124.41 (88.191.124.41) port 80 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18 > Host: 88.191.124.41 > Accept: */* > < HTTP/1.1 200 OK < Date: Fri, 25 Nov 2011 22:11:31 GMT < Server: Apache/2.2.14 (Ubuntu) < Last-Modified: Wed, 25 Aug 2010 08:11:38 GMT < ETag: "840d09-b1-48ea16e57f5a6" < Accept-Ranges: bytes < Content-Length: 177 < Vary: Accept-Encoding < Content-Type: text/html < X-Pad: avoid browser bug < <html><body><h1>It works!</h1> <p>This is the default web page for this server.</p> <p>The web server software is running but no content has been added, yet.</p> </body></html> * Connection #0 to host 88.191.124.41 left intact * Closing connection #0
设置一个等待时间,然后再试一次:
$ echo "GET /" | nc -w 3 88.191.124.41 80