Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教一下,里面的IP有端口的以及没有端口的,如何转为IP.TXT啊?格式好像不一样。 #10

Open
orange1233 opened this issue Jul 19, 2023 · 3 comments

Comments

@orange1233
Copy link

No description provided.

@teng662858
Copy link

+1

@hello-earth
Copy link
Owner

只关注有端口号的就可以了。
没有端口号的ip是落地前的隧道b端ip,如果你看不懂请忽略这句话

@MelodyUSA
Copy link

MelodyUSA commented Jul 24, 2023

用脚本处理就可以了,把以下代码复制保存为一份 *.ps1 文件,放到 txt 目录下运行,就能得到以地区命名的只写有 ip 的 txt,和包含所有 ip 的 all.txt

# 获取当前目录下的所有txt文件
$files = Get-ChildItem -Path . -Filter "*.txt"

# 初始化一个空数组来存储所有IP地址
$allIPs = @()

# 循环处理每个文件
foreach ($file in $files) {
    # 读取文件内容
    $content = Get-Content $file.FullName
    
    # 初始化一个哈希表来存储IP地址对应的机场码
    $ipAirportMap = @{}

    # 提取每一行中的IP地址和机场码,并存储到哈希表中
    foreach ($line in $content) {
        $ipAirport = $line -split '\|' | ForEach-Object { $_.Trim() }
        $ip = ($ipAirport[0] -split ':')[0]
        $airport = $ipAirport[2]
        $ipAirportMap[$ip] = $airport
    }

    # 根据机场码将IP地址保存到对应的文件中
    foreach ($ip in $ipAirportMap.Keys) {
        $airport = $ipAirportMap[$ip]
        $outputFile = "$airport.txt"
        $ip | Out-File -FilePath $outputFile -Append

        # 将IP地址添加到所有IP数组中
        $allIPs += $ip
    }
}

# 将所有IP地址保存到 all.txt 文件中
$allIPs | Out-File -FilePath "all.txt" -Encoding UTF8

Write-Host "All IP addresses have been saved into the all.txt file"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants