Skip to content

Instantly share code, notes, and snippets.

@g3rhard
Last active June 15, 2017 09:15
Show Gist options
  • Save g3rhard/04a0121284ae26d0fb3166df033880b8 to your computer and use it in GitHub Desktop.
Save g3rhard/04a0121284ae26d0fb3166df033880b8 to your computer and use it in GitHub Desktop.
Send IP address with Telegram in Windows OS
@echo off
set ip_address_string="IPv4"
rem Uncomment the following line when using Windows 7 or Windows 8 / 8.1 (with removing "rem")!
rem set ip_address_string="IPv4 Address"
for /f "usebackq tokens=2 delims=:" %%f in (`ipconfig ^| findstr /c:%ip_address_string%`) do (
echo Your IP Address is: %%f
powershell send_telegram.ps1 -chat_id CHAT_ID -text 'Greetings for %computername% with ip %%f'
goto :eof
)
param(
[string]$chat_id = $(Throw "'-chat_id' argument is mandatory"),
[string]$text = $(Throw "'-text' argument is mandatory"),
[switch]$markdown,
[switch]$nopreview
)
$token = "TOKEN"
if($nopreview) { $preview_mode = "True" }
if($markdown) { $markdown_mode = "Markdown" } else {$markdown_mode = ""}
$payload = @{
"chat_id" = $chat_id;
"text" = $text
"parse_mode" = $markdown_mode;
"disable_web_page_preview" = $preview_mode;
}
Invoke-WebRequest `
-Uri ("https://api.telegram.org/bot{0}/sendMessage" -f $token) `
-Method Post `
-ContentType "application/json;charset=utf-8" `
-Body (ConvertTo-Json -Compress -InputObject $payload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment