zoukankan      html  css  js  c++  java
  • 字符串整形

    从网上拿到hosts记录,然后将它整形输出成address=/www.google.com/127.0.0.1这种格式。

    第一个办法有点偷懒,只找出URL列,然后手动在最后加上IP地址。误打误撞学到了Trim的特殊之处。

    第二个办法老老实实把URL列和IP列交换位置,然后输出。

    <#方法一#>
    $result = (Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/vokins/yhosts/master/hosts').content -split "`n"
    ($result | Select-String -Pattern "^127.0.0.1").Line | foreach { 
      'address=/' + $_.TrimStart('.1270').TrimStart() + '/127.0.0.1'
    }
    <#方法二#>
    $result = (Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/vokins/yhosts/master/hosts').content -split "`n"
    ($result | Select-String -Pattern "^127.0.0.1").Line | foreach {
      'address=/' + ($_ -split " ")[1] + "/" + ($_ -split " ")[0]
    }

    将诸如"google.com": 1,这样格式的文本整形成server=/google.com/127.0.0.1#5353输出

    $result = (Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/1265578519/PAC/master/abc.pac').content -split "`n"
    ($result | Select-String -Pattern "`".+`":s1").Line.Trim('",1: ') | foreach {
      'server=/' + $_ + "/127.0.0.1#5353"
    }

    将诸如apnic|CN|ipv4|203.34.39.0|256|20110414|allocated这样格式的文本整形输出成192.168.1.0/24

    $result = (Invoke-WebRequest -Uri 'http://ftp.apnic.net/stats/apnic/delegated-apnic-latest').content -split "`n"
    ($result | Select-String -Pattern ".+CN[|]ipv4[|].+").Line | foreach {
      '-A SHADOWSOCKS -d ' + $_.split('|')[3] + '/' + (32 - [math]::log($_.split('|')[4]) / [math]::Log(2)) + ' -j RETURN'
    }
  • 相关阅读:
    二分题目
    求最小公倍数的最简模板
    用 vue 脚手架 vue-cli 初始化(新建)项目
    电脑没有声音
    node.js 安装步骤
    phpStrom编辑器 通过 git 提交代码到 gitlab
    jq 实现头像(气泡式浮动)
    微信网页授权 、获取用户昵称 头像等信息
    秒格式化 “秒” 为 天 时 分 秒
    改变swiper 按钮swiper-button-next 颜色
  • 原文地址:https://www.cnblogs.com/IvanChen/p/6598555.html
Copyright © 2011-2022 走看看