messpy / local_application

ローカル
1 stars 0 forks source link

スクリプト関係 #4

Open messpy opened 5 months ago

messpy commented 5 months ago

sudo rm -rf /home/kennypi

sudo mkdir /home/kennypi

sudo chown kennypi:kennypi /home/kennypi

messpy commented 5 months ago

アプリケーション:Yahoo! インストールパッケージ名:jp.co.yahoo.android.yjtop 起動:jp.co.yahoo.android.yjtop.YJTopActivity アプリケーション:Y!かんたんバックアップ インストールパッケージ名:jp.co.yahoo.android.ybackup 起動:jp.co.yahoo.android.ybackup.MainActivity アプリケーション:FMラジオ インストールパッケージ名:com.caf.fmradio 起動:com.caf.fmradio.FMRadio アプリケーション:キッズスペース インストールパッケージ名:com.coloros.childrenspace 起動:null アプリケーション:Y!mobile メール インストールパッケージ名:jp.co.yahoo.android.ymobile.mail 起動:jp.co.yahoo.android.ymobile.mail.ui.SplashActivity アプリケーション:テーマストア インストールパッケージ名:com.oplus.themestore 起動:com.nearme.themespace.activities.ThemeActivity アプリケーション:ヘルプ & フィードバック インストールパッケージ名:com.coloros.operationManual 起動:null アプリケーション:安心遠隔ロック/遠隔初期化 インストールパッケージ名:jp.softbank.mb.tdrl 起動:null アプリケーション:あんしんフィルター インストールパッケージ名:jp.softbank.mb.parentalcontrols 起動:jp.co.daj.consumer.ifilter.browser.SplashActivity アプリケーション:ライブ壁紙セレクター インストールパッケージ名:com.android.wallpaper.livepicker 起動:null アプリケーション:ゲーム インストールパッケージ名:com.oplus.games 起動:com.oplus.games.ui.main.MainGameActivity アプリケーション:緊急速報メール インストールパッケージ名:com.google.android.cellbroadcastreceiver 起動:null アプリケーション:緊急速報メール インストールパッケージ名:jp.softbank.mb.cbrl 起動:jp.softbank.mb.cbrl.CBRLauncherActivity

messpy commented 5 months ago

@echo off set /p packagePartName=Enter part of the package name to uninstall: for /f "tokens=*" %%i in ('adb shell pm list packages ^| findstr %packagePartName%') do ( set packageName=%%i set packageName=!packageName:package: =! echo Uninstalling !packageName! adb shell pm uninstall -k --user 0 !packageName! )

messpy commented 5 months ago

@echo off setlocal enabledelayedexpansion

REM 検索するファイル名を設定 set FILENAME=example.txt

REM デバイス上でファイルを検索 for /f "tokens=*" %%i in ('adb shell find / -name %FILENAME%') do ( set FILEPATH=%%i echo Pulling !FILEPATH! adb pull "!FILEPATH!" )

endlocal

messpy commented 5 months ago

@echo off setlocal enabledelayedexpansion

REM 検索するファイル名を設定 set FILENAME=example.txt

REM デバイス上でファイルを検索 for /f "tokens=*" %%i in ('adb shell find / -name %FILENAME%') do ( set FILEPATH=%%i echo Found file: !FILEPATH! set /p PULL="Do you want to pull this file? (y/n): " if /i !PULL!==y ( adb pull "!FILEPATH!" echo File pulled: !FILEPATH! ) else ( echo Skipped file: !FILEPATH! ) )

endlocal

messpy commented 4 months ago
@echo off
setlocal enabledelayedexpansion

REM 実行ファイルのディレクトリを取得
set "base_dir=%~dp0"

REM 監視するフォルダのパス
set "source_folder=%base_dir%source"

REM コピー先のフォルダのパス
set "destination_folder=%base_dir%destination"

REM ファイルの更新日時を保持する変数
set "prev_date="

REM ファイルが更新されたかどうかのフラグ
set "updated=false"

REM フォルダ内のファイルをループ
for %%f in ("%source_folder%\*") do (
    REM ファイルの更新日時を取得
    for /f "tokens=1-3 delims= " %%a in ('dir /T:W "%%f" ^| find "%%~nxf"') do (
        set "file_date=%%a %%b %%c"
    )

    REM 初回の比較用として前回の日時を設定
    if not defined prev_date (
        set "prev_date=!file_date!"
    )

    REM 日時が異なる場合、更新されたと判断
    if "!file_date!" neq "!prev_date!" (
        set "updated=true"
    )
)

REM 更新があった場合、フォルダをコピー
if "!updated!"=="true" (
    REM コピー先のフォルダが存在しない場合は作成
    if not exist "%destination_folder%" (
        mkdir "%destination_folder%"
    )

    REM フォルダをコピー
    xcopy "%source_folder%\*" "%destination_folder%\" /s /e /i /y
    echo Folder copied to %destination_folder%
) else (
    echo No updates found.
)

endlocal
pause

修正ポイントの説明:

  1. ファイルの更新日時を取得する際に、作成日時ではなく更新日時を使用

    • dir /T:W "%%f" ^| find "%%~nxf" コマンドにより、更新日時を取得します。
  2. ファイルが更新されたかどうかのフラグを設定

    • set "updated=false" として初期化し、更新された場合に set "updated=true" と設定します。
  3. コピー先のフォルダが存在しない場合は作成

    • if not exist "%destination_folder%" ( mkdir "%destination_folder%" ) を追加して、コピー先のフォルダが存在しない場合にフォルダを作成します。
  4. フォルダをコピー

    • xcopy "%source_folder%\*" "%destination_folder%\" /s /e /i /y
messpy commented 4 months ago

Option Explicit

Dim fso, folderPath, folder, subFolders, latestFolder, secondLatestFolder Dim latestSize, secondLatestSize, currentDate, newFolderName

folderPath = "C:\path\to\your\folder" ' フォルダのパスを指定

Set fso = CreateObject("Scripting.FileSystemObject") If Not fso.FolderExists(folderPath) Then WScript.Echo "指定されたフォルダが存在しません: " & folderPath WScript.Quit End If

Set folder = fso.GetFolder(folderPath) Set subFolders = folder.SubFolders

' 最新とその次に新しいフォルダを取得 Dim folderArray(), i ReDim folderArray(subFolders.Count - 1) i = 0

Dim subFolder For Each subFolder In subFolders Set folderArray(i) = subFolder i = i + 1 Next

' 作成日でソート Call QuickSort(folderArray, 0, UBound(folderArray))

If UBound(folderArray) >= 1 Then Set latestFolder = folderArray(UBound(folderArray)) Set secondLatestFolder = folderArray(UBound(folderArray) - 1)

latestSize = GetFolderSize(latestFolder)
secondLatestSize = GetFolderSize(secondLatestFolder)

' サイズの比較
If latestSize <> secondLatestSize Then
    currentDate = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2)
    newFolderName = folderPath & "\" & currentDate
    fso.CopyFolder latestFolder.Path, newFolderName
End If

Else WScript.Echo "フォルダが2つ以上存在しません。" End If

' フォルダサイズを取得する関数 Function GetFolderSize(folder) Dim totalSize, subFolder, file totalSize = 0

For Each file In folder.Files
    totalSize = totalSize + file.Size
Next

For Each subFolder In folder.SubFolders
    totalSize = totalSize + GetFolderSize(subFolder)
Next

GetFolderSize = totalSize

End Function

' QuickSortアルゴリズム Sub QuickSort(arr, low, high) Dim i, j, pivot, temp i = low j = high pivot = arr((low + high) \ 2).DateCreated

Do While i <= j
    Do While arr(i).DateCreated < pivot
        i = i + 1
    Loop
    Do While arr(j).DateCreated > pivot
        j = j - 1
    Loop
    If i <= j Then
        Set temp = arr(i)
        Set arr(i) = arr(j)
        Set arr(j) = temp
        i = i + 1
        j = j - 1
    End If
Loop

If low < j Then Call QuickSort(arr, low, j)
If i < high Then Call QuickSort(arr, i, high)

End Sub

messpy commented 4 months ago

Option Explicit

Dim fso, folderPath, folder, subFolders, latestFolder, secondLatestFolder Dim latestSize, secondLatestSize, currentDateTime, newFolderName

folderPath = "C:\path\to\your\folder" ' フォルダのパスを指定

Set fso = CreateObject("Scripting.FileSystemObject") If Not fso.FolderExists(folderPath) Then WScript.Echo "指定されたフォルダが存在しません: " & folderPath WScript.Quit End If

Set folder = fso.GetFolder(folderPath) Set subFolders = folder.SubFolders

' 最新とその次に新しいフォルダを取得 Dim folderArray(), i ReDim folderArray(subFolders.Count - 1) i = 0

Dim subFolder For Each subFolder In subFolders Set folderArray(i) = subFolder i = i + 1 Next

' 作成日でソート Call QuickSort(folderArray, 0, UBound(folderArray))

If UBound(folderArray) >= 1 Then Set latestFolder = folderArray(UBound(folderArray)) Set secondLatestFolder = folderArray(UBound(folderArray) - 1)

latestSize = GetFolderSize(latestFolder)
secondLatestSize = GetFolderSize(secondLatestFolder)

' サイズの比較
If latestSize <> secondLatestSize Then
    currentDateTime = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2) & Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2)
    newFolderName = folderPath & "\" & currentDateTime
    fso.CopyFolder latestFolder.Path, newFolderName
End If

Else WScript.Echo "フォルダが2つ以上存在しません。" End If

' フォルダサイズを取得する関数 Function GetFolderSize(folder) Dim totalSize, subFolder, file totalSize = 0

For Each file In folder.Files
    totalSize = totalSize + file.Size
Next

For Each subFolder In folder.SubFolders
    totalSize = totalSize + GetFolderSize(subFolder)
Next

GetFolderSize = totalSize

End Function

' QuickSortアルゴリズム Sub QuickSort(arr, low, high) Dim i, j, pivot, temp i = low j = high pivot = arr((low + high) \ 2).DateCreated

Do While i <= j
    Do While arr(i).DateCreated < pivot
        i = i + 1
    Loop
    Do While arr(j).DateCreated > pivot
        j = j - 1
    Loop
    If i <= j Then
        Set temp = arr(i)
        Set arr(i) = arr(j)
        Set arr(j) = temp
        i = i + 1
        j = j - 1
    End If
Loop

If low < j Then Call QuickSort(arr, low, j)
If i < high Then Call QuickSort(arr, i, high)

End Sub

messpy commented 4 months ago

Option Explicit

Dim fso, folderPath, folder, subFolders, latestFolder, secondLatestFolder Dim latestSize, secondLatestSize, currentDateTime, NewFolderName Dim shell Set shell = CreateObject("WScript.Shell")

Dim objFSO Set objFSO = CreateObject("Scripting.FileSystemObject")

folderPath = shell.CurrentDirectory Set fso = CreateObject("Scripting.FileSystemObject") If Not fso.FolderExists(folderPath) Then MsgBox "指定されたフォルダが存在しません: " & folderPath WScript.Quit End If

Set folder = fso.GetFolder(folderPath) Set subFolders = folder.SubFolders

' 最新とその次に新しいフォルダを取得 Dim folderArray(), i ReDim folderArray(subFolders.Count - 1) i = 0

Dim subFolder For Each subFolder In subFolders Set folderArray(i) = subFolder i = i + 1 Next

' 作成日でソート Call QuickSort(folderArray, 0, UBound(folderArray))

If UBound(folderArray) >= 1 Then Set latestFolder = folderArray(UBound(folderArray)) Set secondLatestFolder = folderArray(UBound(folderArray) - 1)

latestSize = GetFolderSize(latestFolder)
secondLatestSize = GetFolderSize(secondLatestFolder)

' サイズの比較
If latestSize <> secondLatestSize Then
    currentDateTime = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2) & Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2)

    ' "WORK" を削除
    Dim latestFolderName,latestFolderName2
    latestFolderName = latestFolder.Name
    latestFolderName2 = Replace(latestFolderName, "WORK_", "")
    objFSO.GetFolder(latestFolderName).Name=latestFolderName2
    newFolderName = folderPath & "\WORK_" & currentDateTime
    fso.CopyFolder latestFolder.Path, newFolderName
Else
    MsgBox "フォルダのサイズに変更はありません。"
End If

Else MsgBox "フォルダが2つ以上存在しません。" End If

' フォルダサイズを取得する関数 Function GetFolderSize(folder) Dim totalSize, subFolder, file totalSize = 0

For Each file In folder.Files
    totalSize = totalSize + file.Size
Next

For Each subFolder In folder.SubFolders
    totalSize = totalSize + GetFolderSize(subFolder)
Next

GetFolderSize = totalSize

End Function

' QuickSortアルゴリズム Sub QuickSort(arr, low, high) Dim i, j, pivot, temp i = low j = high pivot = arr((low + high) \ 2).DateCreated

Do While i <= j
    Do While arr(i).DateCreated < pivot
        i = i + 1
    Loop
    Do While arr(j).DateCreated > pivot
        j = j - 1
    Loop
    If i <= j Then
        Set temp = arr(i)
        Set arr(i) = arr(j)
        Set arr(j) = temp
        i = i + 1
        j = j - 1
    End If
Loop

If low < j Then Call QuickSort(arr, low, j)
If i < high Then Call QuickSort(arr, i, high)

End Sub

messpy commented 4 months ago

Option Explicit

Dim fso, shell, folderPath, folder, subFolders, latestFolder, secondLatestFolder Dim latestSize, secondLatestSize, currentDateTime, newFolderName

' WScript.Shell オブジェクトを作成して現在の作業フォルダを取得 Set shell = CreateObject("WScript.Shell") folderPath = shell.CurrentDirectory ' 現在の作業フォルダを使用

Set fso = CreateObject("Scripting.FileSystemObject") If Not fso.FolderExists(folderPath) Then MsgBox "指定されたフォルダが存在しません: " & folderPath WScript.Quit End If

Set folder = fso.GetFolder(folderPath) Set subFolders = folder.SubFolders

' 最新とその次に新しいフォルダを取得 Dim folderArray(), i ReDim folderArray(subFolders.Count - 1) i = 0

Dim subFolder For Each subFolder In subFolders Set folderArray(i) = subFolder i = i + 1 Next

' 作成日でソート Call QuickSort(folderArray, 0, UBound(folderArray))

If UBound(folderArray) >= 1 Then Set latestFolder = folderArray(UBound(folderArray)) Set secondLatestFolder = folderArray(UBound(folderArray) - 1)

latestSize = GetFolderSize(latestFolder)
secondLatestSize = GetFolderSize(secondLatestFolder)

' サイズの比較
If latestSize <> secondLatestSize Then
    currentDateTime = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2) & Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2)

    ' 新しいフォルダ名を設定
    newFolderName = folderPath & "\WORK_" & currentDateTime

    ' 最新フォルダを新しいフォルダ名でコピー
    fso.CopyFolder latestFolder.Path, newFolderName
Else
    MsgBox "フォルダのサイズに変更はありません。"
End If

Else MsgBox "フォルダが2つ以上存在しません。" End If

' フォルダサイズを取得する関数 Function GetFolderSize(folder) Dim totalSize, subFolder, file totalSize = 0

For Each file In folder.Files
    totalSize = totalSize + file.Size
Next

For Each subFolder In folder.SubFolders
    totalSize = totalSize + GetFolderSize(subFolder)
Next

GetFolderSize = totalSize

End Function

' QuickSortアルゴリズム Sub QuickSort(arr, low, high) Dim i, j, pivot, temp i = low j = high pivot = arr((low + high) \ 2).DateCreated

Do While i <= j
    Do While arr(i).DateCreated < pivot
        i = i + 1
    Loop
    Do While arr(j).DateCreated > pivot
        j = j - 1
    Loop
    If i <= j Then
        Set temp = arr(i)
        Set arr(i) = arr(j)
        Set arr(j) = temp
        i = i + 1
        j = j - 1
    End If
Loop

If low < j Then Call QuickSort(arr, low, j)
If i < high Then Call QuickSort(arr, i, high)

End Sub

messpy commented 4 months ago

Option Explicit

Dim fso, shell, folderPath, folder, subFolders, latestFolder, secondLatestFolder Dim latestSize, secondLatestSize, currentDateTime, newFolderName

' WScript.Shell オブジェクトを作成して現在の作業フォルダを取得 Set shell = CreateObject("WScript.Shell") folderPath = shell.CurrentDirectory ' 現在の作業フォルダを使用

Set fso = CreateObject("Scripting.FileSystemObject") If Not fso.FolderExists(folderPath) Then MsgBox "指定されたフォルダが存在しません: " & folderPath WScript.Quit End If

Set folder = fso.GetFolder(folderPath) Set subFolders = folder.SubFolders

' 最新とその次に新しいフォルダを取得 Dim folderArray(), i ReDim folderArray(subFolders.Count - 1) i = 0

Dim subFolder For Each subFolder In subFolders Set folderArray(i) = subFolder i = i + 1 Next

' 作成日でソート Call QuickSort(folderArray, 0, UBound(folderArray))

If UBound(folderArray) >= 1 Then Set latestFolder = folderArray(UBound(folderArray)) Set secondLatestFolder = folderArray(UBound(folderArray) - 1)

latestSize = GetFolderSize(latestFolder)
secondLatestSize = GetFolderSize(secondLatestFolder)

' サイズの比較
If latestSize <> secondLatestSize Then
    currentDateTime = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2) & Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2)

    ' 新しいフォルダ名を設定
    newFolderName = folderPath & "\WORK_" & currentDateTime

    ' 最新フォルダを新しいフォルダ名でコピー
    fso.CopyFolder latestFolder.Path, newFolderName
Else
    MsgBox "フォルダのサイズに変更はありません。"
End If

' 最新フォルダ以外の "WORK" を含むフォルダ名から "WORK" を削除
For i = 0 To UBound(folderArray)
    If Not folderArray(i).Path = latestFolder.Path Then
        Dim oldName, newName
        oldName = folderArray(i).Name
        If InStr(oldName, "WORK") > 0 Then
            newName = Replace(oldName, "WORK", "")
            fso.MoveFolder folderArray(i).Path, folder.Path & "\" & newName
        End If
    End If
Next

Else MsgBox "フォルダが2つ以上存在しません。" End If

' フォルダサイズを取得する関数 Function GetFolderSize(folder) Dim totalSize, subFolder, file totalSize = 0

For Each file In folder.Files
    totalSize = totalSize + file.Size
Next

For Each subFolder In folder.SubFolders
    totalSize = totalSize + GetFolderSize(subFolder)
Next

GetFolderSize = totalSize

End Function

' QuickSortアルゴリズム Sub QuickSort(arr, low, high) Dim i, j, pivot, temp i = low j = high pivot = arr((low + high) \ 2).DateCreated

Do While i <= j
    Do While arr(i).DateCreated < pivot
        i = i + 1
    Loop
    Do While arr(j).DateCreated > pivot
        j = j - 1
    Loop
    If i <= j Then
        Set temp = arr(i)
        Set arr(i) = arr(j)
        Set arr(j) = temp
        i = i + 1
        j = j - 1
    End If
Loop

If low < j Then Call QuickSort(arr, low, j)
If i < high Then Call QuickSort(arr, i, high)

End Sub

messpy commented 4 months ago

Option Explicit

Dim fso, shell, folderPath, folder, subFolders, latestFolder, secondLatestFolder Dim latestSize, secondLatestSize, currentDateTime, newFolderName

' WScript.Shell オブジェクトを作成して現在の作業フォルダを取得 Set shell = CreateObject("WScript.Shell") folderPath = shell.CurrentDirectory ' 現在の作業フォルダを使用

Set fso = CreateObject("Scripting.FileSystemObject") If Not fso.FolderExists(folderPath) Then MsgBox "指定されたフォルダが存在しません: " & folderPath WScript.Quit End If

Set folder = fso.GetFolder(folderPath) Set subFolders = folder.SubFolders

' サブフォルダの数を確認 Dim subFolderCount subFolderCount = subFolders.Count

If subFolderCount = 1 Then ' フォルダが1つしかない場合 Dim singleFolder For Each singleFolder In subFolders currentDateTime = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2) & Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) newFolderName = folderPath & "\WORK_" & currentDateTime fso.CopyFolder singleFolder.Path, newFolderName MsgBox "フォルダが1つしかないため、コピーしました。新しいフォルダ名: " & newFolderName Next ElseIf subFolderCount >= 2 Then ' フォルダが2つ以上ある場合 Dim folderArray(), i ReDim folderArray(subFolderCount - 1) i = 0

Dim subFolder
For Each subFolder In subFolders
    Set folderArray(i) = subFolder
    i = i + 1
Next

' 作成日でソート
Call QuickSort(folderArray, 0, UBound(folderArray))

Set latestFolder = folderArray(UBound(folderArray))
Set secondLatestFolder = folderArray(UBound(folderArray) - 1)

latestSize = GetFolderSize(latestFolder)
secondLatestSize = GetFolderSize(secondLatestFolder)

' サイズの比較
If latestSize <> secondLatestSize Then
    currentDateTime = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2) & Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2)

    ' 新しいフォルダ名を設定
    newFolderName = folderPath & "\WORK_" & currentDateTime

    ' 最新フォルダを新しいフォルダ名でコピー
    fso.CopyFolder latestFolder.Path, newFolderName

    ' 最新フォルダ以外の "WORK" を含むフォルダ名から "WORK" を削除
    For i = 0 To UBound(folderArray)
        If Not folderArray(i).Path = latestFolder.Path Then
            Dim oldName, newName
            oldName = folderArray(i).Name
            If InStr(oldName, "WORK") > 0 Then
                newName = Replace(oldName, "WORK", "")

objFSO.GetFolder(oldrName).Name=newName fso.MoveFolder folderArray(i).Path, folder.Path & "\" & newName End If End If Next Else MsgBox "フォルダのサイズに変更はありません。" End If Else MsgBox "フォルダが2つ以上存在しません。" End If

' フォルダサイズを取得する関数 Function GetFolderSize(folder) Dim totalSize, subFolder, file totalSize = 0

For Each file In folder.Files
    totalSize = totalSize + file.Size
Next

For Each subFolder In folder.SubFolders
    totalSize = totalSize + GetFolderSize(subFolder)
Next

GetFolderSize = totalSize

End Function

' QuickSortアルゴリズム Sub QuickSort(arr, low, high) Dim i, j, pivot, temp i = low j = high pivot = arr((low + high) \ 2).DateCreated

Do While i <= j
    Do While arr(i).DateCreated < pivot
        i = i + 1
    Loop
    Do While arr(j).DateCreated > pivot
        j = j - 1
    Loop
    If i <= j Then
        Set temp = arr(i)
        Set arr(i) = arr(j)
        Set arr(j) = temp
        i = i + 1
        j = j - 1
    End If
Loop

If low < j Then Call QuickSort(arr, low, j)
If i < high Then Call QuickSort(arr, i, high)

End Sub

messpy commented 4 months ago

Private Sub Worksheet_Change(ByVal Target As Range) Dim r As Range Dim cell As Range

' 監視範囲を設定
Set r = Range("C3:C10")

' 変更されたセルが監視範囲内であるかを確認
If Not Intersect(Target, r) Is Nothing Then
    Application.EnableEvents = False
    For Each cell In Intersect(Target, r)
        ' 変更されたセルの同じ行のF列に現在時刻を記録
        Cells(cell.Row, "F").Value = Now
    Next cell
    Application.EnableEvents = True
End If

End Sub

messpy commented 4 months ago

sudo tail -f /var/log/auth.log # Ubuntu / Debian 系 sudo tail -f /var/log/secure # CentOS / Fedora / RHEL 系

messpy commented 4 months ago

sudo apt update sudo apt install openssh-server sudo systemctl enable ssh sudo systemctl start ssh

messpy commented 4 months ago

sudo apt update sudo apt install openssh-server sudo systemctl enable ssh sudo systemctl start ssh

messpy commented 4 months ago

import tkinter as tk import json

JSONファイルに保存する関数

def save_list(): with open("saved_list.json", "w") as file: json.dump(right_list.get(0, tk.END), file)

JSONファイルから読み込む関数

def load_list(): with open("saved_list.json", "r") as file: items = json.load(file) for item in items: right_list.insert(tk.END, item)

繰り返し回数の取得

def get_repeat_count(): return int(repeat_count_entry.get())

繰り返し実行関数

def execute_repeated(): repeat_count = get_repeatcount() for in range(repeat_count): for item in right_list.get(0, tk.END): execute_command(item)

GUI構築

root = tk.Tk()

繰り返し回数入力フィールド

repeat_count_entry = tk.Entry(root) repeat_count_entry.pack()

リストボックス

left_list = tk.Listbox(root) left_list.pack(side=tk.LEFT)

right_list = tk.Listbox(root) right_list.pack(side=tk.RIGHT)

保存・読み込みボタン

save_button = tk.Button(root, text="保存", command=save_list) save_button.pack()

load_button = tk.Button(root, text="呼び出し", command=load_list) load_button.pack()

繰り返し実行ボタン

execute_button = tk.Button(root, text="繰り返し実行", command=execute_repeated) execute_button.pack()

root.mainloop()

messpy commented 4 months ago

import tkinter as tk from tkinter import filedialog, messagebox import time import subprocess import json import pyautogui

def adbcmd(command): try: result = subprocess.run(command, shell=True, capture_output=True, text=True) output_text.insert(tk.END, result.stdout + '\n') output_text.see(tk.END) except subprocess.CalledProcessError as e: output_text.insert(tk.END, f"Error: {e.stderr}\n") output_text.see(tk.END)

def execute_pyautogui(action, params): try: getattr(pyautogui, action)(**params) except Exception as e: output_text.insert(tk.END, f"Error executing pyautogui action: {e}\n") output_text.see(tk.END)

class DragDropListbox(tk.Listbox): def init(self, master, kwargs): super().init(master, kwargs) self.bind('', self.save_mouse_pos) self.bind('', self.move_item) self.start_index = None

def save_mouse_pos(self, event):
    self.start_index = self.nearest(event.y)

def move_item(self, event):
    new_index = self.nearest(event.y)
    if new_index != self.start_index:
        items = list(self.get(0, tk.END))
        item = items.pop(self.start_index)
        items.insert(new_index, item)
        self.delete(0, tk.END)
        for item in items:
            self.insert(tk.END, item)
        self.start_index = new_index

def countdown(seconds): for remaining in range(seconds, 0, -1): output_text.insert(tk.END, f"Waiting for {remaining} seconds...\n") output_text.see(tk.END) root.update() time.sleep(1) output_text.insert(tk.END, "Waiting complete!\n") output_text.see(tk.END)

def on_ok_button_click(): repeat_count = repeat_var.get() if repeat_count == "∞": while True: execute_actions() else: for i in range(int(repeat_count), 0, -1): output_text.insert(tk.END, f"Repeat count: {i}\n") output_text.see(tk.END) root.update() execute_actions()

def execute_actions(): items = listbox_right.get(0, tk.END) for item in items: if item.startswith("adbcmd:"): command = item.split(':', 1)[1] adbcmd(command) elif item.startswith("timesleep:"): wait_time = int(item.split(':', 1)[1]) countdown(wait_time) elif item.startswith("pyautogui:"): action_data = json.loads(item.split(':', 1)[1]) execute_pyautogui(action_data['action'], action_data['params']) elif item.startswith("print:"): message = item.split(':', 1)[1] output_text.insert(tk.END, f"{message}\n") output_text.see(tk.END) elif item.startswith("subprocess:"): command = item.split(':', 1)[1] adbcmd(command)

def on_drag(event): selected_indices = listbox_left.curselection() if selected_indices: selected = listbox_left.get(selected_indices[0]) entry_value = entry_input.get()

    if selected == "timesleep":
        if entry_value.isdigit():
            listbox_right.insert(tk.END, f"{selected}:{entry_value}")
        else:
            messagebox.showerror("Input Error", "Please enter a valid number for timesleep.")
    elif selected == "pyautogui":
        try:
            action_data = json.loads(entry_value)
            listbox_right.insert(tk.END, f"pyautogui:{json.dumps(action_data)}")
        except json.JSONDecodeError:
            messagebox.showerror("Input Error", "Please enter valid JSON for pyautogui action.")
    elif selected == "subprocess":
        listbox_right.insert(tk.END, f"subprocess:{entry_value}")
    else:
        listbox_right.insert(tk.END, f"print:{entry_value}")

    entry_input.delete(0, tk.END)

def on_delete_button_click(): selected_indices = listbox_right.curselection() for index in reversed(selected_indices): listbox_right.delete(index)

def on_delete_key(event): selected_indices = listbox_right.curselection() if selected_indices: listbox_right.delete(selected_indices[0])

def load_from_json(): file_path = filedialog.askopenfilename(filetypes=[("JSON Files", "*.json")]) if file_path: with open(file_path, 'r', encoding='utf-8') as file: commands = json.load(file) for command in commands: listbox_left.insert(tk.END, f"subprocess:{command}")

root = tk.Tk() root.title("Drag and Drop Listboxes")

menu_bar = tk.Menu(root) root.config(menu=menu_bar)

file_menu = tk.Menu(menu_bar, tearoff=0) menu_bar.add_cascade(label="File", menu=file_menu) file_menu.add_command(label="Load", command=load_from_json)

frame = tk.Frame(root) frame.pack(padx=10, pady=10)

listbox_left = tk.Listbox(frame, selectmode=tk.SINGLE) listbox_left.grid(row=0, column=0, padx=10)

listbox_right = DragDropListbox(frame, selectmode=tk.SINGLE) listbox_right.grid(row=0, column=1, padx=10)

listbox_left.insert(tk.END, "print") listbox_left.insert(tk.END, "timesleep") listbox_left.insert(tk.END, "pyautogui") listbox_left.insert(tk.END, "subprocess")

listbox_left.bind('', on_drag)

repeat_var = tk.StringVar(value="1") repeat_options = ["1", "2", "3", "5", "10", "∞"] repeat_menu = tk.OptionMenu(root, repeat_var, *repeat_options) repeat_menu.pack(side=tk.LEFT, padx=5)

ok_button = tk.Button(root, text="OK", command=on_ok_button_click) ok_button.pack(side=tk.LEFT, pady=5)

delete_button = tk.Button(root, text="Delete", command=on_delete_button_click) delete_button.pack(pady=5)

label_input = tk.Label(root, text="Enter value:") label_input.pack(pady=5)

entry_input = tk.Entry(root) entry_input.pack(pady=5)

output_frame = tk.Frame(root) output_frame.pack(padx=10, pady=10)

output_text = tk.Text(output_frame, wrap=tk.WORD, height=10, width=50) output_text.pack()

root.bind('', on_delete_key)

root.mainloop()

messpy commented 4 months ago

chmod +x ssh_info.sh

./ssh_info.sh

!/bin/bash

ローカルIPアドレスを取得

LOCAL_IP=$(hostname -I | awk '{print $1}')

パブリックIPアドレスを取得

PUBLIC_IP=$(curl -s ifconfig.me)

ユーザー名を取得

USER_NAME=$(whoami)

SSHポート番号を取得

SSH_PORT=$(grep '^Port ' /etc/ssh/sshd_config | awk '{print $2}')

ポート番号が設定されていない場合、デフォルトの22を使用

if [ -z "$SSH_PORT" ]; then SSH_PORT=22 fi

出力

echo "SSH接続情報:" echo "ローカルIPアドレス: $LOCAL_IP" echo "パブリックIPアドレス: $PUBLIC_IP" echo "ユーザー名: $USER_NAME" echo "ポート番号: $SSH_PORT"

messpy commented 4 months ago

sudo systemctl stop fail2ban sudo systemctl disable fail2ban

messpy commented 4 months ago

adb shell sh /storage/emulated/0/Android/data/moe.shizuku.privileged.api/start.sh