Exit Telnet Through Batch File - email

I've been asked to write a script in work that will send an email to our support email if an IP stops allowing us access to telnet on port 23. I've got the gist of what I need, but when the IP doesn't deny access, the script opens telnet and I can't get it to close using a command in the batch file.
This is what I've got so far. Sorry if there is already a question which answers this, I haven't been able to find it.
#ECHO OFF
set IPADDRESS=1.2.3.4
set INTERVAL=5
telnet %IPADDRESS% 23
if errorlevel 1 GOTO LOG
:LOG
ECHO %DATE% %TIME% %IPADDRESS% Could Not Be Reached >> failurelog.txt
GOTO MAIL
:MAIL
blat -install smtpserver
blat failurelog.txt -to email -subject "%IPADDRESS% Is Down"
timeout %INTERVAL%
exit

Related

Use mail command in terminal to send emails and specify From address

I have tried to send thousands of emails through running a csh script to execute the "mail" command. But all my emails were blocked by the recipient. I was told that the blocking reason is because of the workstation domain (kichisatoru#Sky.local), which is not a real domain (e.g. xx#gmail.com). How can I fix this issue, so the recipient can receive my emails in the standard way?
My csh:
#!/bin/csh
foreach eml (`ls *.eml`)
mail recipient#edu < $eml
echo $eml sent...
end
My problem is fixed! I have found a very detailed manual online http://www.developerfiles.com/how-to-send-emails-from-localhost-mac-os-x-el-capitan/

Sending email with blat does not work even with stunnel

I've been looking everywhere for this answer and have had no luck! I went to http://www.jeffkastner.com/2010/01/blat-stunnel-and-gmail/ and followed it step by step. Stunnel installed, installed service and started service successfully but blat still does not work after setting it up.
I have a folder on my desktop C:\Users\Nicholas\Desktop\Games which is where the contents of blat is placed, and C:\Users\Nicholas\Desktop\Games\stunnel is where stunnel files are installed. And I also tried this when stunnel was installed to program files and it still did not work. I don't want blat installed to system32 because I have a batch file I'm using it with in C:\Users\Nicholas\Desktop\Games.
Online I try to find syntax for the blat -install but none of them work or at least I dont understand how it works. This is what I believe:
You need to install your profile
You send an email using the profile (ex: blat -p gmailsmtp ...)
And thats it? It doesn't work for me.
I am willing to find an alternative to blat, but if you give an alternative please give a tutorial, not a suggestion.
Here are the install commands for blat I tried: (Which one should be working?)
blat -install smtp.gmail.com
blat -install smtp.gmail.com myemail#gmail.com -u username(does this include #gmail.com?) -pw password – - gmailsmtp
Here are email commands I tried:
blat -p gmailsmtp -to myemail#gmail.com -subject "subject text" -body "Body text" -server 127.0.0.1:1099
and a lot more commands that I can't remember.
Anyway, anyone find where I tripped here?
Yes! I found a vbscript script that finally worked! On this thread, "Email sending not working", Miguel posted the following script
Sub SendGMail()
' Object creation
Set objMsg = CreateObject("CDO.Message")
Set msgConf = CreateObject("CDO.Configuration")
' Server Configuration
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user#gmail.com"
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
msgConf.Fields.Update
' Email
objMsg.To = "user#gmail.com"
objMsg.From = "fromuser#domain.com"
objMsg.Subject = "Test send with Gmail account"
objMsg.HTMLBody = "HTML/Plain text message."
objMsg.Sender = "Mr. Name"
Set objMsg.Configuration = msgConf
' Send
objMsg.Send
' Clear
Set objMsg = nothing
Set msgConf = nothing
End Sub
This script is working, but a lot of people still had problems, looking closer into the script I realized I didn't even recall the SendGMail()! To make this work I simply typed SendGMail() on the next line and BAM! I got an email! Thank you #user4317867 for helping me find my answer.

Messages Using Command prompt in Windows 7

How to send message over network using command prompt in windows 7 ?
"net send" is a command using a background service called "messenger".
This service has been removed from Windows 7. ie You cannot use 'net send' on Vista nor Win7 / Win8.
Pity though , I loved using it.
There is alternatives, but that requires you to download and install software on each pc you want to use, this software runs as background services, and i would advise one to be very very very very careful of using these kind of software as they can potentially cause seriously damage one's system or impair the systems securities.
winsent innocenti /
winsent messenger
****This command is risky because of what is stated above***
Type "msg /?" in the command prompt to get various ways of sending meessages to a user.
Type "net send /?" in the command prompt to get another variation of sending messages across.
You can use the net send command to send a message over a network.
example:
net send * How Are You
you can use the above statement to send a message to all members of your domain.But if you want to send a message to a single user named Mike, you can use net send mike hello!
this will send hello! to the user named Mike.
Open Notepad and write this
#echo off
:A
Cls
echo MESSENGER
set /p n=User:
set /p m=Message:
net send %n% %m%
Pause
Goto A
and then save as "Messenger.bat" and close the Notepad
Step 1:
when you open that saved notepad file it will open as a file Messenger command prompt
with this details.
Messenger
User:
after "User" write the ip of the computer you want to contact and then press enter.

Email an alert when sFTP connection cannot be reached?

I have a very small office environment, and my team sends created pdfs to an sFTP server daily.
Occasionally, I will get a call that someone can't log in to upload the files.
My normal course of action is to connect to the sFTP server myself, run a commmand like ls to determine it is responding.
I would like to be able to automate this with notification if there is a failure:
Login to the sFTP server (with credentials).
Run an LS command
Email if connection times out or login fails.
I have limited experience with writing Batch files, but I can't seem to figure a way to get only a 'failed' / no response to send an email.
Could anyone help with ideas? I'd like to run this as a VB or Batch in Scheduled Tasks, as I have a Server 2000 machine this could run on. I know batch has issue sending emails, but i have another batch file that uses Blat.exe to send an email with passed variables, so i could use that if i could get batch to send failed responses...
You should be able to do this with a batch file.
Create a file called logon.ftp. This file contains the FTP logon script. Mine contains:
open Ftp_server
ftpuser
ftppassword
ls -l
quit
The testftp.bat file:
ftp.exe < logon.ftp | grep "Not connected" > nul && call :alert_someone
#echo Logon successful
goto exit
:alert_someone
#echo %date% %time% > alert.txt
#echo ftp_server appears to not be taking logins. >> alert.txt
blat alert.txt -to you -from ftp_watcher -subject "alert %date% %time% ftp_server not taking logins"
:exit
You'll need to get blat, and grep so you can do the string checking. My winxp ftp doesnt support errorlevels, so I'm using the errorlevel returned from grepping the 'Not connected' string to figure out if this worked or not.
You can get wget or curl to do this as well, and they do support errorlevels.
Batch files can be a bit too basic for this kind of thing.
If you were able and willing to experiment with the Python programming language ( http://www.python.org ) and additionally install the Paramiko module ( http://www.lag.net/paramiko/ ) then it would be possible to write a script along the lines of...
import paramiko
try:
t = paramiko.Transport(('TheHostname', 22))
t.connect(username='MyUsername', password='MyPassword')
sftp = paramiko.SFTPClient.from_transport(t)
dirlist = sftp.listdir('.')
except:
print "It's Broken"
#Send e-mails and such here
that you could then schedule to run on a regular basis.

Win XP: If NET SEND is disabled, is there still a way to send messages across network via cmd?

I'm working on a project that will popup on a logged in network computer, but hit a stall when I realized that NET SEND isn't enabled on the network. Is there another viable option (assuming regular user privileges on the network)?
Net send doesn't exist anymore since Win XP.
I've done some research recently and this is the alternative I found:
MSG.EXE
usage: msg /server:servername *(=all sessions) /time:timeout message
If you get an "error 5" you need to change this registry key on the receiver's computer:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server]
"AllowRemoteRPC"=dword:00000001
(I don't know if AllowRemoteRPC is also used for other things, so use at own risk)
If you still get an "error 5" you need to add the receiver's credentials to the sender's Credential Manager, under "Windows Credentials"
This is an easy-to-use batch file I made for the use of MSG.exe
#echo off
:server
cls
set /p server=Computer name of receiver:
:delay
cls
set /p time=Message time-out (sec), 0 is none:
:start
echo Enter "exit" to stop. "Delay" to change delay. "Receiver" to change receiver.
set /p message=Enter message:
if "%message%" == "exit" goto stop
if "%message%" == "delay" goto delay
if "%message%" == "receiver" goto server
cls
msg /server:%server% * /time:%time% %message%
echo Message sent: %message%
goto start
:stop
Hope this helps!