Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8234451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:28:58+00:00 2026-06-07T18:28:58+00:00

This is what i want to accomplish using php (possibly using exce()?): telnet to

  • 0

This is what i want to accomplish using php (possibly using exce()?):

  1. telnet to a whois registrar using a program called proxychains:

    proxychains telent whois.someregistrar 43

  2. if failed -> try 1 again

  3. feed a domain name to the connection:

    somedomainname.com

  4. capture data returned by the registrar to php

I have no experience with shell scripting so how do i capture the event
in which telnet is connected and hangs for input and how do i “feed” it?

Am i totaly off here or is this the right way to go about it?

EDIT: i see python have a good way to handel this using expect

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:29:00+00:00Added an answer on June 7, 2026 at 6:29 pm

    Here is a basic working example.

    <?php
    
    $whois   = 'whois.isoc.org.il';            // server to connect to for whois
    $data    = 'drew.co.il';                   // query to send to whois server
    $errFile = '/tmp/error-output.txt';        // where stderr gets written to
    $command = "proxychains telnet $whois 43"; // command to run for making query
    
    // variables to pass to proc_open
    $cwd            = '/tmp';
    $env            = null;
    $descriptorspec = array(
            0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
            1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
            2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
    );
    
    // process output goes here
    $output  = '';
    
    // store return value on failure
    $return_value = null;
    
    // open the process
    $process = proc_open($command, $descriptorspec, $pipes, $cwd, $env);
    
    if (is_resource($process)) {
        echo "Opened process...\n";
    
        $readBuf = '';
    
        // infinite loop until process returns
        for(;;) {
            usleep(100000); // dont consume too many resources
    
            // TODO: implement a timeout
    
            $stat = proc_get_status($process); // get info on process
    
            if ($stat['running']) { // still running
                $read = fread($pipes[1], 4096);
                if ($read) {
                    $readBuf .= $read;
                }
    
                // read output to determine if telnet connected successfully
                if (strpos($readBuf, "Connected to $whois") !== false) {
                    // write our query to process and append newline to initiate
                    fwrite($pipes[0], $data . "\n");
    
                    // read the output of the process
                    $output = stream_get_contents($pipes[1]);
                    break;
                }
            } else {
                // process finished before we could do anything
                $output       = stream_get_contents($pipes[1]); // get output of command
                $return_value = $stat['exitcode']; // set exit code
                break;
            }
        }
    
        echo "Execution completed.\n";
    
        if ($return_value != null) {
            var_dump($return_value, file_get_contents($errFile));
        } else {
            var_dump($output);
        }
    
        // close pipes
        fclose($pipes[1]);
        fclose($pipes[0]);
    
        // close process
        proc_close($process);
    } else {
        echo 'Failed to open process.';
    }
    

    This is meant to be run from the command line, but it doesn’t have to be. I tried to comment it fairly well. Basically at the beginning you can set the whois server, and the domain to query.

    The script uses proc_open to open a proxychains process that calls telnet. It checks to see if the process was opened successfully, and if so check that its status is running. While its running, it reads the output from telnet into a buffer and looks for the string telnet outputs to indicate we are connected.

    Once it detects telnet connected, it writes the data to the process followed by a newline (\n) and then reads the data from the pipe where the telnet data goes. Once that happens it breaks out of the loop and closes the process and handles.

    You can view the output from proxychains from the file specified by $errFile. This contains the connection information as well as debug information in the event of a connection failure.

    There is probably some additional error checking or process management that may need to be done to make it more robust, but if you put this into a function you should be able to easily call it and check the return value to see if the query was successful.

    Hope that gives you a good starting point.

    Also check out this answer of mine for another working example of proc_open, this example implements a timeout check so you can bail if the command hasn’t completed in a certain amount of time: Creating a PHP Online Grading System on Linux: exec Behavior, Process IDs, and grep

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to accomplish this (mysql) query: UPDATE table SET field = field +
I want to accomplish nearly the same thing as this question , which is
This question does pretty much what I want to accomplish, but my table is
What I want to accomplish is the effect I have seen in this site
I am using PHP to match the following data type : [[1200,135],[127,13]] I want
I am creating a game web site using PHP and I want to just
Let say i want to read a text file using php. Now my text
I am trying to accomplish something like this : <?php $url = 'http://www.mydomain.com/img/picture.jpg'; ?>
How do I get and print a char from a user? This want do
I want this highchart - http://jsfiddle.net/zPDca/ inside a popup. But if i decrease its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.