首页 > 系统相关 >PowerShell 调用接口插入模拟数据

PowerShell 调用接口插入模拟数据

时间:2023-02-23 12:55:38浏览次数:39  
标签:调用 58.619 Get Random 接口 session URandom InputObject PowerShell

 

 

 

function insertUser($i = 2) {
    $str ="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"  # 字符串
     # echo $str.ToCharArray()
    Try {  
        for ($x = 1; $x -lt $i; $x = $x + 1) {   
            $small = "a","b","c","d","e","f","g","h","i","j","k","m","n","p","q","r","s","t","u","v","w","x","y","z"
            $big = "A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z"
            $number = "1","2","3","4","5","6","7","8","9","0"
            # $symbol = "~","!","@","#","$","%","^","&","*","(",")"
            $mDate =get-date -format "yyyyMMdd hh:mm:ss"
        
            $p1 = Get-Random -InputObject $small
            $p2 = Get-Random -InputObject $small
            $p3 = Get-Random -InputObject $big
            $p4 = Get-Random -InputObject $big
            $p5 = Get-Random -InputObject $number
            $p6 = Get-Random -InputObject $number
            #$p7 = Get-Random -InputObject $symbol
            $URandom = $p4 + $p1 + $p3 + $p2 + $p4 + $p5 + $p6 +$p4 + $p1 +$p5 
            $PRandom = $p5+3 +$6 + 8*2+123

            $session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
            $session.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
            $session.Cookies.Add((New-Object System.Net.Cookie("vue_admin_template_token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwibmlja25hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJtYWlsIjoiU3VwZXJBZG1pblN5c3RlbUAxNjMuY29tIiwiand0Q3JlYXRlZCI6IjIwMjMvMi8yMyA5OjQ1OjU1Iiwiand0RXhwaXJlZCI6IjIwMjMvMy8yIDk6NDU6NTUiLCJuYmYiOjE2NzcxMTY3NTUsImV4cCI6MTY3NzExNjc2MiwiaXNzIjoiV2ViQXBwSXNzdWVyIiwiYXVkIjoiV2ViQXBwQXVkaWVuY2UifQ.D6vXY9LkAdc7kj-XpoEf_ct2J-xvm4cTLtbYuRcrjiQ", "/", "47.103.68.175")))
            Invoke-WebRequest -UseBasicParsing -Uri "http://47.103.**.***:8888/prod-api/Admin/User/AddUser" `
            -Method "POST" `
            -WebSession $session `
            -Headers @{
                "Accept"="application/json, text/plain, */*"
                "Accept-Encoding"="gzip, deflate"
                "Accept-Language"="zh-CN,zh;q=0.9"
                "Origin"="http://47.103.**.***:8888"
                "Referer"="http://47.103.**.***:8888/"
                "X-Token"="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwibmlja25hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJtYWlsIjoiU3VwZXJBZG1pblN5c3RlbUAxNjMuY29tIiwiand0Q3JlYXRlZCI6IjIwMjMvMi8yMyA5OjQ1OjU1Iiwiand0RXhwaXJlZCI6IjIwMjMvMy8yIDk6NDU6NTUiLCJuYmYiOjE2NzcxMTY3NTUsImV4cCI6MTY3NzExNjc2MiwiaXNzIjoiV2ViQXBwSXNzdWVyIiwiYXVkIjoiV2ViQXBwQXVkaWVuY2UifQ.D6vXY9LkAdc7kj-XpoEf_ct2J-xvm4cTLtbYuRcrjiQ"
            } `
            -ContentType "application/json;charset=UTF-8" `
            -Body ([System.Text.Encoding]::UTF8.GetBytes("{`"id`":0,`"userName`":`"$URandom`",`"password`":`"$PRandom`",`"nickName`":`"$URandom`",`"eMail`":`"[email protected]`",`"active`":true,`"roles`":[`"employee`"],`"rolesList`":[{`"id`":0,`"userId`":0,`"name`":`"employee`",`"description`":`"$([char]26222)$([char]36890)$([char]29992)$([char]25143)`"}],`"token`":{`"id`":0,`"userId`":0,`"token`":`"`",`"createTime`":`"2023-02-23T02:39:58.619Z`",`"expireTime`":`"2023-02-23T02:39:58.619Z`"},`"introduction`":`"`",`"avatar`":`"avatar.gif`",`"remark`":`"`",`"params`":`"`",`"attr1`":`"`",`"createUser`":`"Register`",`"createTime`":`"2023-02-23T02:39:58.619Z`",`"updateUser`":`"Register`",`"updateTime`":`"2023-02-23T02:39:58.619Z`"}"))
        }
    }  
    catch {  
        "Error in a Try block."  
    }
}

insertUser(50000)

 

标签:调用,58.619,Get,Random,接口,session,URandom,InputObject,PowerShell
From: https://www.cnblogs.com/xfweb/p/17147557.html

相关文章