在 Perl 中使用不同的出站 IP
我们在同一台服务器上运行了几个不同的网站,它们都访问 1 个特定的 Web 服务,每个网站都有自己唯一的 API 密钥。不幸的是,网络服务有基于 IP 地址(而不是 API 密钥)的每日限制,因此虽然我们的每个网站都低于其每日限制,但综合起来它们却超出了 IP 限制。当通过 Web 浏览器访问时,每个网站都在不同的静态 IP 地址上运行,但是当 Perl 脚本在每个网站用户帐户的下运行时,它们的出站 IP 地址是相同的。
我的问题是如何才能使每个 perl 脚本都使用特定站点的正确 IP 地址,以便每个脚本都能保持在 Web 服务的每日限制内?更简单地说,perl 脚本如何使用 LWP perl 模块更改其发出的调用的出站 IP 地址?解释很棒,但代码示例会更好。
预先感谢您的帮助!
We have a few different websites running on the same server that all access 1 particular web service with each having their own unique API key. Unfortunately the web service has a daily limit based on IP address (not API key) so while each of our sites is way under their daily limit, combined they are over the IP limit. When accessed via a web browser each website runs on a different static IP address, however when perl scripts are run under each of the website user account's their outbound IP address is identical.
My question is how can I make it so that each perl script uses the correct IP address of the particular site so that each one can stay within the daily limit of the web service? More simply, how can a perl script change the outbound IP address of the calls it's is making using the LWP perl module? Explanations are great but code examples would be even better.
Thanks in advance for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 LWP::UserAgent 您可以简单地使用 ''local_address'' 方法来决定您想要哪个 IP 地址用于传出连接:
Using LWP::UserAgent you can simply use the ''local_address'' method to decide which IP address you want for outgoing connections: