Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^6: Querying program port

by CougarXR7 (Acolyte)
on Aug 11, 2019 at 15:32 UTC ( [id://11104287]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Querying program port
in thread Querying program port


"What program are you typing "status" into?"< status is not being typed into a program
but a Ubuntu terminal after the ip&port has been entered.
The same terminal that would run this script.
Sir, I owe you 2 apologies,
1. I was told the query was UDP but they are wrong it's TCP.
2. It's a game server status query and not player stats.
I ran a different game on my main computer with win10.
To my right is my Ubuntu box, accessing a terminal I typed in my ip and game's UDP port,
it returned nothing, changed port to TCP and got server info:
\status\
\gamename\JetFighter\gamever\0.9\location\1\hostname\Cats Lair\hostport\8181\mapname\Armed Bandits
\gametype\Deathmatch\numplayers\1\maxplayers\16\gamemode\openplaying\timelimit\240\fraglimit\50\
teamplay\0\player_0\Cougar\frags_0\0\deaths_0\0\skill_0\0\ping_0\0\team_0\Team 0\final\\queryid\3.1
Do you have access to a terminal? , "nc 333networks.com 27900 -u" enter without quotes, then enter \status\ , you'll get game server info.
I used netstat, comparing before running my friend's game server and while running the game server.
Using the ports that showed up while running the server still returned nothing.
Having a terminal run script named, severstatus.pl (script name, example:)
Script runs with printing data on terminal to show terminal is running script.
"ip port"/ enter
\status\ enter
Server returns/replies, exiting script, printing info on terminal.
NO return/reply, script must access "ctrl+c" to start a terminal new session.
inc port by 1.
Now with the same ip and a new port number (inc by 1) entered in a new terminal session followed by \status\
This continues until game server replies to the query.
I hope I cleared up anymore questions you have, if not please ask away!
Friday I ordered the book from amazon "Learning Perl", not sure how many years it will take me but I will try!
Sir, I cannot thank you enough for helping me! Thank you!
Should you decide to write this script, you can use "333networks" query to test it. Starting with port 27895, watch it inc on terminal until it incs to 27900, and get a return/reply.

Replies are listed 'Best First'.
Re^7: Querying program port
by jcb (Parson) on Aug 12, 2019 at 00:34 UTC

    Here is a Perl solution that not only indicates which port answered, but also decodes that backslash-delimited blob into a nicely formatted list.

    This script takes full advantage of UDP by sending all of the queries before attempting to read a response.

    #!/usr/bin/perl # A simple tool to find a UDP server on a known host, adapted from an # example in perlipc. The server speaks a strange protocol. # This script is free software; you can redistribute it and/or modify +it # under the same terms as Perl itself. use strict; use warnings; use Socket; # Configuration my $HOST_ADDR = '333networks.com'; my @PORTS = (27895 .. 27905); my $TIMEOUT = 3.0; # seconds # Translate network addresses my $Host = inet_aton $HOST_ADDR; my $UDP_Protocol = getprotobyname 'udp'; # Open socket socket(SOCKET, PF_INET, SOCK_DGRAM, $UDP_Protocol) or die "socket: $!" +; # Go! foreach my $port (@PORTS) { defined(send(SOCKET, qq[\\status\\], 0, sockaddr_in($port, $Host))) or die "send: $!" } # Any replies within timeout period? my @Reports = (); # each element: [$sockaddr, $data] my $Start_time = time; my $rout; my $rin = ''; vec($rin, fileno(SOCKET), 1) = 1; while ((time < ($Start_time + 2*$TIMEOUT)) && (select($rout = $rin, undef, undef, $TIMEOUT))) { my $remote_sockaddr; my $report; ($remote_sockaddr = recv(SOCKET, $report, 4096, 0)) or die "recv: $! +"; push @Reports, [$remote_sockaddr, $report]; } # Parse and pretty-print unless (scalar @Reports) { print "No responses received.\n"; exit 1 } foreach my $report (@Reports) { my ($remote_port, $remote_address) = sockaddr_in $report->[0]; my @rows = (); # cannot use hash due to duplicate keys { local $_ = $report->[1]; # \---- $1: key $2: value ----\ while (m/\\([^\\]+)\\([^\\]*)(?=\\|\z)/gs) { push @rows, [$1, $2] +} } my $namewidth = 0; foreach my $row (@rows) { $namewidth = length $row->[0] if length $row->[0] > $namewidth } print "Response from port $remote_port:\n"; printf ' %*s: %s%s', $namewidth, @$_, "\n" for @rows; } exit 0 __END__

    Sample output:

    Response from port 27900: gamename: 333networks gamever: MS-perl 2.4.3 location: 0 queryid: 72.1 hostname: master.errorist.tk (The Errorist Network Master Server) hostport: 28900 gametype: MasterServer mapname: 333networks numplayers: 14 maxplayers: 2965 gamemode: openplaying queryid: 72.2 mutators: 333networks synchronization, UCC Master applet synchron +ization, Server Status Checker AdminName: Syntax-Error AdminEMail: syntax@errorist.tk queryid: 72.3 final:

    Your homework assignment is to learn enough of Perl to explain how this script works. I have used some odd features and deliberately written parts of the script to illustrate some features of Perl that I would not have used if this were not intended as a teaching aid. Learning Perl enough to complete this assignment may take a while, so you are not expected to present it here for grading, only to yourself. And remember, if you cheat on this assignment, you are only cheating yourself.

      Thank you! I tried sending you a PM but I need to learn how to use this forum. I will be sending you a pm once I learn how.
      Tried running script in terminal and it gave me a Permission denied.

        Did you try running it as perl findgame.pl (or whatever name you assigned to it)? That is usually a local error, related to the file not being marked executable. Also try: chmod a+x findgame.pl (or whatever name you saved it as).

        You have a pm. ... I tried sending you a PM... I will be sending you a pm...

        Just out of curiosity, what's a "PM"?


        Give a man a fish:  <%-{-{-{-<

Re^7: Querying program port
by jcb (Parson) on Aug 11, 2019 at 23:39 UTC

    Well, 333networks.com resolves to 54.236.6.225 here, but I get no responses, not even to ping, from that address. I have tried connecting with TCP to port 27900 with no response to the connection attempt. I have tried sending UDP packets with both "status\n" and "status\r\n" with no response, not even an ICMP error.

    Of course I have all the terminals I want here... but if that server refuses to talk to me, that is a bit of a problem... wait a minute...

    You keep putting backslashes around "status"... (echo -ne '\status\'; sleep 1) | socat STDIO UDP4:333networks.com:27900 produces

    \gamename\333networks\gamever\MS-perl 2.4.3\location\0\queryid\41.1\ho +stname\master.errorist.tk (The Errorist Network Master Server)\hostpo +rt\28900\gametype\MasterServer\mapname\333networks\numplayers\14\maxp +layers\2965\gamemode\openplaying\queryid\41.2\mutators\333networks sy +nchronization, UCC Master applet synchronization, Server Status Check +er\AdminName\Syntax-Error\AdminEMail\syntax@errorist.tk\queryid\41.3\ +final\

    It is using UDP. And the first thing you need to study is "quoting".

    The server is firewalled: an incorrect packet or a packet sent to the wrong port elicits no response at all, while '\status\' sent to the correct port produces that response. I have a bone to pick with whomever designed that atrocity of a protocol, but I think I can make a simple "shotgun query" tool. As a proof of concept, here is a simple solution at the shell:

    (for port in `seq 27895 1 27905`; do (echo -ne '\status\'; sleep 1) | socat STDIO UDP4:333networks.com:${port} & done; sleep 1; echo '')

    Paste that into a terminal and observe the results. That one does not tell you which port responded, only the response that was received, but the returned "hostport" happens to be 1000 higher than the port that produces the response. Writing this in Perl will be a fun exercise.

    Note that I am deliberately designing this in a way that will set off alarms and get you caught if you try to use it as a system cracking tool.

    2019-08-12 Athanasius fixed long line.

    2019-08-12 jcb concurs with this edit to his node and thanks Athanasius. Let us see if I remember how to fix this the next time I need it...

      Sir, I am no hacker/cracker/internet punk!

      I pasted in terminal, (for port in `seq 27895 1 27905`; do (echo -ne '\status\'; sleep 1) | socat STDIO UDP4:333networks.com:${port} & done; sleep 1; echo '') , it returned nothing.

      In my previous post I told you it was TCP. Jetfighter game port 8181 is UDP, I tried it first, no response, tried TCP port 8182 and got a response.
      Pasting this, nc 333networks.com 27900 -u into a terminal, enter, followed by \status\ , enter
      should of gave you a return/reply. Since it was a UDP port, my bad I am learning this as I go.
      You have a pm.

        Apologies, but we have had such unsavory characters seek to abuse the Monastery in the past, and your initial request seemed somewhat fishy. You were making a round-about request for a "port scanner", which can have legitimate uses like yours, but is also a well-known cracker tool. Later interactions have cleared up my suspicions.

        The command you gave uses netcat to exchange UDP packets (the -u selects UDP) with port 27900 on 333networks.com. I have socat installed, which is a similar, but somewhat more advanced (and complex) program. It is possible there may be some portability issues between our shells or other system weirdness. The Perl version should have solved that problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11104287]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-24 01:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found