VB icon

IP Look-up (PHP-GTK)

Submitted on: 1/1/2015 9:27:00 AM
By: Josh Sherman (from psc cd)  
Level: Intermediate
User Rating: By 7 Users
Compatibility: PHP 4.0
Views: 2366
     Looks up the IP address for a domain. DON'T FORGET TO RATE MY CODE!

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
// Name: IP Look-up (PHP-GTK)
// Description:Looks up the IP address for a domain. DON'T FORGET TO RATE MY CODE!
// By: Josh Sherman (from psc cd)
// Assumes:Usage: php -q ip_lookup.php

 * ip_lookup.php - My first attempt at PHP-GTK.
 * Author: Josh Sherman
 * Purpose: Looks up the IP address for a domain.
 * Usage: php -q ip_lookup.php
// Check to see if the PHP-GTK extension is available.
if (!class_exists('gtk')) {
	if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
// Called when delete-event takes place, tells it to proceed.
function delete_event()
	return false;
// Called when the window is being destroyed, tells it to quit the main loop.
function destroy()
// Called when the button is clicked, looks up the IP and places it in the 
// entry box.
function get_ip()
	global 	$text;
	global	$domain;
	global	$window;
	global	$ip_address;
	$domain = $text->get_text();
	$ip_address = gethostbyname($domain);
// Creates a new top-level window and connect the signals to the appropriate
// functions.
$window = &new GtkWindow();
$window->connect('destroy', 'destroy');
$window->connect('delete-event', 'delete_event');
$window->set_title('IP Look-up');
$window->set_policy(false, false, false);
// Creates a table to place the widgets in, and adds it to the window.
$grid = &new GtkTable(2, 2);
// Creates a label to describe the entry field and adds it to the table.
$label = &new GtkLabel();
$grid->attach($label, 0, 1, 0, 1);
// Creates an entry field and adds it to the table.
$text = &new GtkEntry();
$grid->attach($text, 1, 2, 0, 1);
// Creates tooltips object for the entry field.
$ttentry = &new GtkTooltips();
$ttentry->set_tip($text, 'Type the domain you want to look up here.', '');
// Creates a button, connects its clicked signal to the get_ip() function and 
// adds the button to the window.
$button = &new GtkButton('Get IP');
$button->connect('clicked', 'get_ip');
$grid->attach($button, 0, 2, 1, 2);
// Creates tooltips object for the button.
$ttbutton = &new GtkTooltips();
$ttbutton->set_tip($button, 'Looks up the IP', '');
// Show the window and all of it's child widgets.
// Set focus to the entry field.
// Run the main loop.

Other 12 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.