Distributions
› Ubuntu
› Fedora
› CentOS
中文资源站
› 网易开源镜像站
AntonChen
V2EX  ›  Linux

如何让 xxx.com 在 shell 脚本执行时指向 1.2.3.4 ?

  •  
  •   AntonChen ·
    antonchen · Jul 7, 2017 · 4121 views
    This topic created in 3417 days ago, the information mentioned may be changed or developed.

    就是想在脚本中能解析成其它结果而不影响系统本身解析

    Supplement 1  ·  Jul 7, 2017

    说我发了个奇怪网站的请关掉科学上网,(我真的是随手敲的

    这个问题如果能实现那么脚本会少写很多(我以为和脚本指定时区、语言之类的有什么特殊操作),虽然还有一堆其它方式去达成目的....

    23 replies  •  2017-07-14 16:13:19 +08:00
    Tink
    Tink
    Jul 7, 2017 via iPhone
    1
    都指定 ip 了为什么非要解析?直接访问 ip 就行了呗
    pangliang
    pangliang
    Jul 7, 2017
    2
    @Tink 因为一个 ip 上可能有多个域名站点
    AntonChen
    AntonChen
    OP
    Jul 7, 2017
    3
    @Tink 我想了半天无言以对,但我还是想知道能不能这么干
    ywgx
    ywgx
    Jul 7, 2017
    4
    如果感觉需求比较怪异,那就是上层设计出问题了,建议从头考虑
    AntonChen
    AntonChen
    OP
    Jul 7, 2017
    5
    @pangliang 按照 @Tink 的说法其实你可以手动加 Header.... 总之我想了半天确实有各种方式去实现直接用 IP,但我还是想知道能不能在 shell 脚本中解析。
    LioMore
    LioMore
    Jul 7, 2017
    6
    楼主你发了一个黄网你知道吗
    LioMore
    LioMore
    Jul 7, 2017
    7
    建议标题改为 example.com
    AntonChen
    AntonChen
    OP
    Jul 7, 2017
    8
    @LioMore 我刚刚特地打开试了下,WTF 我不是故意的....
    AntonChen
    AntonChen
    OP
    Jul 7, 2017
    9
    @LioMore #7 已经改不了了...
    LioMore
    LioMore
    Jul 7, 2017
    10
    @AntonChen 哈哈哈,那好吧
    hljjhb
    hljjhb
    Jul 7, 2017 via Android
    11
    @AntonChen 也取决于你要在脚本里如何使用 像 curl 可以指定 dns
    wuruxu
    wuruxu
    Jul 7, 2017❤️1
    12
    curl -v https://www.example.com --resolve www.example.com:443:192.168.10.11
    est
    est
    Jul 7, 2017
    13
    自己撸个 LD_PRELOAD 然后把 gethostbyname 给撸了。
    GOOD21
    GOOD21
    Jul 7, 2017
    14
    @LioMore 哈哈哈哈哈,果然。
    AntonChen
    AntonChen
    OP
    Jul 7, 2017
    15
    @hljjhb @wuruxu 不是 HTTP 请求,如果能直接实现我描述那样脚本会少写很多

    @est #13 我是个只会写 Shell 的菜逼
    geelaw
    geelaw
    Jul 7, 2017 via Android
    16
    更简单的做法是重新配置服务器的域名映射,然后用 script./debug. 开头的子域来写代码。
    justfly
    justfly
    Jul 7, 2017
    18
    curl -H "Host:www.example.com" "1.2.3.4:443/some/api"
    Tink
    Tink
    Jul 7, 2017 via iPhone
    19
    @pangliang 你构造一个请求头就行了啊
    dallaslu
    dallaslu
    Jul 7, 2017
    20
    用 docker 呢?把 hosts 文件扔在容器里。
    Martin9
    Martin9
    Jul 7, 2017
    21
    妈的在公司点进去吓死了。。
    mingyun
    mingyun
    Jul 7, 2017
    22
    @Martin9 哈哈 尴尬了
    ytlm
    ytlm
    Jul 14, 2017
    23
    @LioMore 正在上班呢!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2008 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 10:05 · PVG 18:05 · LAX 02:05 · JFK 05:05
    ♥ Do have faith in what you're doing.