gw_1966 Posted February 1, 2008 Share Posted February 1, 2008 Hi.I have written a port listening tool that will allow a machine to "listen" on one or more ports.http://www.autoitscript.com/forum/index.ph...mp;#entry403227Is there anyway to have a welcome message if I use telnet to connect to the machine. At the moment it connects fine, but I would like telnet to to say "You have successfully connected to machine xxx".ThanksGrant CheersGrant Link to comment Share on other sites More sharing options...
James Posted February 1, 2008 Share Posted February 1, 2008 Use a MsgBox() to do this, if it's successful then MsgBox or if there is an error then MsgBox with the error! Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
gw_1966 Posted February 10, 2008 Author Share Posted February 10, 2008 Use a MsgBox() to do this, if it's successful then MsgBox or if there is an error then MsgBox with the error!Hi.But this would only work if I create an Autoit connect program. Sometimes I dont have an option to get files onto the remote machine I am testing connection from. If I use the default windows telnet program that is commonly available on the machine, this would not be able to use msgbox() option. Or am I missing something? Can you elaborate or give us a quick demo script?Thanks. CheersGrant Link to comment Share on other sites More sharing options...
Uten Posted February 11, 2008 Share Posted February 11, 2008 Cant you just use TCPSend($ConnectedSocket, "HELO" & @CR) when something connects to the port? Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
gw_1966 Posted February 12, 2008 Author Share Posted February 12, 2008 Cant you just use TCPSend($ConnectedSocket, "HELO" & @CR) when something connects to the port?Thanks to all for all your help, but once again, this would only work if I use create an autoit code to connect to the portlisten program. Using the command telnet <computername to connect to> <port number listening> comes back with a blank black box. I will continue to investigate. I dont want to have a messagebox on the portlisten side, but on the telnet side.Grant. CheersGrant Link to comment Share on other sites More sharing options...
Uten Posted February 13, 2008 Share Posted February 13, 2008 I Think you have to review your code. This slightly modified (Search for ;NOTE) helpfile sample for TCPRecv works as expected with telnet. Obviously you will have to add more code to make a proper server.. expandcollapse popup#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) ;============================================== ;============================================== ;SERVER!! Start Me First !!!!!!!!!!!!!!! ;============================================== ;============================================== Example() Func Example() ; Set Some reusable info ; Set your Public IP address (@IPAddress1) here. ; Local $szServerPC = @ComputerName ; Local $szIPADDRESS = TCPNameToIP($szServerPC) Local $szIPADDRESS = @IPAddress1 Local $nPORT = 33891 Local $MainSocket, $GOOEY, $edit, $ConnectedSocket, $szIP_Accepted Local $msg, $recv ; Start The TCP Services ;============================================== TCPStartup() ; Create a Listening "SOCKET". ; Using your IP Address and Port 33891. ;============================================== $MainSocket = TCPListen($szIPADDRESS, $nPORT) ; If the Socket creation fails, exit. If $MainSocket = -1 Then Exit ; Create a GUI for messages ;============================================== $GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ")", 300, 200) $edit = GUICtrlCreateEdit("", 10, 10, 280, 180) GUISetState() ; Initialize a variable to represent a connection ;============================================== $ConnectedSocket = -1 ;Wait for and Accept a connection ;============================================== Do $ConnectedSocket = TCPAccept($MainSocket) Until $ConnectedSocket <> -1 ; Get IP of client connecting $szIP_Accepted = SocketToIP($ConnectedSocket) ;NOTE: Added TCPSend to pass on a msg to the aoolication connected TCPSend($ConnectedSocket, "Welcom stranger" & @CRLF & "You are now connected") ; GUI Message Loop ;============================================== While 1 $msg = GUIGetMsg() ; GUI Closed ;-------------------- If $msg = $GUI_EVENT_CLOSE Then ExitLoop ; Try to receive (up to) 2048 bytes ;---------------------------------------------------------------- $recv = TCPRecv($ConnectedSocket, 2048) ; If the receive failed with @error then the socket has disconnected ;---------------------------------------------------------------- If @error Then ExitLoop ; Update the edit control with what we have received ;---------------------------------------------------------------- If $recv <> "" Then GUICtrlSetData($edit, _ $szIP_Accepted & " > " & $recv & @CRLF & GUICtrlRead($edit)) WEnd If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket) TCPShutdown() EndFunc ;==>Example ; Function to return IP Address from a connected socket. ;---------------------------------------------------------------------- Func SocketToIP($SHOCKET) Local $sockaddr, $aRet $sockaddr = DllStructCreate("short;ushort;uint;char[8]") $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _ "ptr", DllStructGetPtr($sockaddr), "ptr", DllStructGetSize($sockaddr)) If Not @error And $aRet[0] = 0 Then $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3)) If Not @error Then $aRet = $aRet[0] Else $aRet = 0 EndIf $sockaddr = 0 Return $aRet EndFunc ;==>SocketToIP Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now