从 IMAP 邮箱中的电子邮件获取 IP
你好 我希望编写一个独立的脚本来登录电子邮件帐户 [IMAP],获取每封电子邮件的标题,找到并查看电子邮件的标题。存储每个人的(发送者或服务器)IP 地址。我认识到这必须有点全面才能涵盖排名前 3 的网络邮件提供商(雅虎、谷歌和 Hotmail)以及其他常见的标头格式。
理想情况下,我想获取发件人的 IP 地址,但会选择服务器的 IP 地址。
我需要在常规 LAMP 设置中用 PHP 执行此操作。
任何想法都会有所帮助。谢谢。
Hello
I am looking to write an independent script to log into an e-mail account [IMAP], get the headers for each e-mail, locate & store the (sender's or server's) IP address from each one. I recognize that this has to be a bit comprehensive to cover the top 3 webmail providers (Yahoo, Google & Hotmail) as well as the other common header formats.
Ideally, I would like to get the senders' IP addresses, but would settle for the servers' IP addresses.
I need to do this in PHP in a regular LAMP setup.
Any ideas would help. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
系统经过的服务器的详细信息按时间倒序显示在电子邮件标题的顶部 - 最近的服务器位于顶部,第一个服务器位于底部。
一个快速、即兴的解决方案是使用 RegExp 尝试找到包含 IP 地址的底部“Received:...”行。
一个非常快速的测试表明:
将匹配线路,并返回 IP 地址。
然后,您只需使用
preg_match_all()
之类的方法来返回匹配行的数组,并使用该批次中的最后一个。The details of the servers the system transits through are shown in the top of the email header in reverse-chronological order - the most recent are at the top, the first servers are at the bottom.
A quick, off-the-cuff solution would be to use a RegExp to try and find the bottom "Received:..." line containing an IP address.
A very quick test suggests that:
will match the lines, and return IP addresses.
Then you'd just use something like
preg_match_all()
to return an array of matched lines, and use the last one of the lot.该IP是发送邮件的服务器的IP,而不是发件人的IP。您想要服务器 IP 还是发送者 IP?
That IP is IP of server who mailed it, not the sender IP. Do you want servers IP or senders IP?
连接后,获取消息列表,现在正在查找消息:
这对我来说轻而易举。
After you connected, got the messages list and now is foreaching a message:
It works like a breeze for me.
我知道这篇文章很旧,但上面选择的答案确实获得了 IP,但不一定获得正确的发送服务器 IP 地址。下面是我用来获取实际发送服务器 IP 的正则表达式:
I know this post is old but the above selected answer does get an IP but it does not necessarily get the correct sending server IP address. Below is the regex I used to get the actual sending servers IP: