从文本文件中查找IP地址 [英] find IP address from a text file

查看:123
本文介绍了从文本文件中查找IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友......

我有一个问题是从给定的文本文件中找出IP地址。

任务是:

一个名为conf.txt的文件。

在conf.txt中存在很多字符串(例如:ahcvyuADD 192.168.0.1 Z q % Z rtZq%Zrt5644585854554bvdfvvdtGHFJ GGHcbvvnnjkk122.16.8.90hh)。



,但是我们知道conf.txt文件中还有三个IP地址,并且ip地址不能继续(两个ip地址之间必须存在一些字符)。



请告诉我哪个条件我应该申请找到IP地址..



谢谢.....

Hello Friends...
I have a problem to find out IP Addresses from a given text file.
The Task is:
A file is given named conf.txt.
In conf.txt a lot of strings are present(like: ahcvyuADD����192.168.0.1��Z���q�%�Z��rt�������Z���q�%�Z��rt�5644585854554bvdfvvdtGHFJ GGHcbvvnnjkk122.16.8.90hh).

but we know there are three IP address also present in conf.txt file and ip addresses are not continue(some characters must present between two ip address).

Please suggest me which condition I should apply to find the ip address..

thanks.....

推荐答案

如果你可以使用正则表达式:

If you can, use a Regex:
(?<First>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?<Second>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?<Third>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?<Fourth>2[0-4]\d|25[0-5]|[01]?\d\d?)





如果你不能,那么你需要手动处理文件,扫描一个数字,最多查找两个,然后是一个点,然后是1到3位,然后是一个点等。如果你找到完全有效的信息,它可能是一个IP地址!如果你不这样做,继续寻找...我没有捷径,我很害怕。



If you can't, then you will need to handle the file manually, and scan for a digit, look for up to two more, followed by a dot, then 1 to 3 digits, then a dot, etc. If you find fully valid info, it's probably an IP address! If you don't, keep looking... There is no "short cut" on that, I'm afraid.


这篇关于从文本文件中查找IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆