简体   繁体   English

用于ip到主机名查找的Python脚本

[英]Python script for ip to hostname lookup

I have never attempted to create a script in my entire life but I've come across an issue where I would require a script (preferably Python) to perform lookups. 我一生中从未尝试过创建脚本,但我遇到了一个需要脚本(最好是Python)来执行查找的问题。 I have a system that actively monitors web and ftp traffic and I'm able to get the sender IP address (typically the web proxy) but the proxies are not passing credentials at this time. 我有一个主动监视Web和ftp流量的系统,我能够获取发送方IP地址(通常是Web代理),但代理目前没有通过凭据。

I'd like to create a script that takes the sender-ip address, queries our internal DNS server, and provides me with the hostname of the machine real time. 我想创建一个脚本,它接收sender-ip地址,查询我们的内部DNS服务器,并为我提供机器实时的主机名。 At that point, I would be able to take the response from DNS and perform a secondary LDAP query to return additional attributes but I'm stuck on step one. 此时,我将能够从DNS获取响应并执行辅助LDAP查询以返回其他属性,但我仍然坚持第一步。

I apologize if this is a very simple script but I've been looking and unfortunately my background is not in scripting, so this is all very new to me. 我很抱歉,如果这是一个非常简单的脚本,但我一直在寻找,不幸的是我的背景不是脚本,所以这对我来说都是新的。 Please let me know if you require any additional info. 如果您需要任何其他信息,请告诉我。

Thanks! 谢谢!

Python 3.3.1 (default, Apr 17 2013, 22:30:32) 
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.gethostbyaddr('74.125.225.35')
('ord08s06-in-f3.1e100.net', [], ['74.125.225.35'])
>>> socket.gethostbyaddr('74.125.225.35')[0]
'ord08s06-in-f3.1e100.net'

Call the python script from whatever app you have that acquires the connecting IP address and pass the IP as a command line parameter. 从您获取连接IP地址的任何应用程序调用python脚本,并将IP作为命令行参数传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM