Connect to <Insert ip here> @ port <insert port her

How would i create a script to connect to an ip at a port and then eventually disconnect?

thanx :twisted:

At its simplest level, you can use telnet:

do shell script “telnet <host.domain.dom> ”

will open a TCP connection to port on the machine <host.domain.dom>

Although I’m guessing you want to do something more than just open the connection…?

2 things how would i log onto that using a username/passwrd
and how can i disconnect

ahh, I knew there was more to just wanting to connect.

As to how to log in, that depends on the protocol you’re using. Since telnet can connect to arbitrary ports it’s not necessarily a telnet login you need… you could be using a HTTP GET, irc login, etc., so to answer your question I’d need to know what you’re trying to log into to be certain, but in general:

do shell script is totally non interactive. You can’t monitor the progress of the shell script, send additional commands, or anything else, only get the output of the command (if there is any).

If using the termlnal’s ‘do script’ command you have the option of targetting a specific window, so something like this might work:

tell application “Terminal”
do script “telnet 6667” – this will open a new window
delay 2 – wait a little for the connection to come up
do script “PASS myPassword” in window 1 – send the password
do script “NICK myNick” in window 1 – send the nickname
do script “USER myUser . . myUser” in window 1 – send the username
end tell

this script will open a new terminal window and login to an irc server running on the specified server/port. You should be able to adjust this script to your needs.

As for disconnecting, that, again, typically depends on the connection type. In the case of irc, ‘do script “QUIT”’ will close the connection.

i am connecting to a game server

there is the ip and ports (1144)
what is the best way to connect (do stuff) and disconnect

i just need the connecting and disconnecting


Ok, but with what app do you do the stuff you want to do? You have to connect through that app so that app is the one who’s connected. If you’ll use the terminal you can just use the first part of the script Camelot wrote above. If want to use another app you’ll have to tell us what app, since thats the app that needs to be scripted.