python ip地址频率扫描器

发布于 2025-01-09 08:15:41 字数 721 浏览 3 评论 0原文

我正在尝试创建一个可以扫描日志的程序。然后显示日志中最频繁的地址。就是这样,但我需要一些帮助......

 def analyse_logs():
open File = open('text.txt', "r")

readLines = openFile.read()
# pat = re.compile("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
wordfreq = {}

for word in readLines.split():
    if word not in wordfreq:
        wordfreq[word] = 1
    else:
        wordfreq[word] += 1

print(wordfreq)

def extract_ip():
for line in string:
    line = line.rstrip()
    result = pattern.search(line)


 def most_frequent():
counter = 0
num = List[0]

for i in List:
    curr_frequency = List.count(i)
    if (curr_frequency > counter):
        counter = curr_frequency
        num = i

return num

 def main():


 if__name__=="_main_":

I am trying to create a programme that will scan a log. The most freqeunt address in the log is then displayed. That is it but i need a bit of help with it please...

 def analyse_logs():
open File = open('text.txt', "r")

readLines = openFile.read()
# pat = re.compile("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
quot;)
wordfreq = {}

for word in readLines.split():
    if word not in wordfreq:
        wordfreq[word] = 1
    else:
        wordfreq[word] += 1

print(wordfreq)

def extract_ip():
for line in string:
    line = line.rstrip()
    result = pattern.search(line)


 def most_frequent():
counter = 0
num = List[0]

for i in List:
    curr_frequency = List.count(i)
    if (curr_frequency > counter):
        counter = curr_frequency
        num = i

return num

 def main():


 if__name__=="_main_":

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琴流音 2025-01-16 08:15:41
def sorting(filename):
    infile = open(filename)
    ip_addr = []
    for line in infile:
        temp = line.split()
    for i in temp:
        ip_addr.append(i)
    infile.close()
    ip_addr.sort()
    outfile = open("result.txt", "w")
    for i in ip_addr:
        outfile.writelines(i)
    outfile.writelines(" ")
    outfile.close()
    sorting("sample_log_1.txt")

    ip_count_dict = {}
    ip_list = ['1.1.1.1', '1.1.1.2', '1.1.1.3', '1.1.1.1']
    # Loop and count ips

    # Final version of ip_count_dict {'1.1.1.1':2 , '1.1.1.2':1, '1.1.1.3':1}

我认为这可能会更容易

def sorting(filename):
    infile = open(filename)
    ip_addr = []
    for line in infile:
        temp = line.split()
    for i in temp:
        ip_addr.append(i)
    infile.close()
    ip_addr.sort()
    outfile = open("result.txt", "w")
    for i in ip_addr:
        outfile.writelines(i)
    outfile.writelines(" ")
    outfile.close()
    sorting("sample_log_1.txt")

    ip_count_dict = {}
    ip_list = ['1.1.1.1', '1.1.1.2', '1.1.1.3', '1.1.1.1']
    # Loop and count ips

    # Final version of ip_count_dict {'1.1.1.1':2 , '1.1.1.2':1, '1.1.1.3':1}

I thought this might be easier

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文