Raised This Month: $ Target: $400
 0% 

missed


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-02-2010 , 23:49   Re: /ip = show server IP
Reply With Quote #6

This will handle if the server doesn't respond and parsing is simplified.
PHP Code:
#include <amxmodx>
#include <sockets>

new const Version[] = "0.1";

const 
TASK_GETIP 3467;

new 
g_szServerIP16 ];

public 
plugin_init() 
{
    
register_plugin"Get Internet IP" Version "bugsy" );
    
    
register_clcmd"say /ip" "GetIP" );
}

public 
GetIPid )
{
    if ( 
g_szServerIP] )
    {
        
client_printid print_chat "* Server IP is [ %s ]" g_szServerIP );
        return;
    }
    
    new 
iSocket iError;
    
    
iSocket socket_open"checkip.dyndns.com" 80 SOCKET_TCP iError );
    
    if ( !
iSocket || iError )
    {
        
client_printid print_chat "* Error creating socket, unable to obtain IP" );
        return;
    }
        
    
socket_sendiSocket "GET / HTTP/1.1^nHost: checkip.dyndns.com^n^n" 42 );
    
    new 
iData];
    
iData] = iSocket;
    
iData] = id;
    
iData] = get_systime();
    
    
set_task0.2 "RecvData" TASK_GETIP iData sizeofiData ) , "b" );
}

public 
RecvDataiData] )
{
    static 
szData256 ] , iStartPos iEndPos;
    new 
iSocket iData];
    new 
iRequestPlayer iData];
    new 
iRequestTime iData];
    
    if ( 
socket_changeiSocket ) )
    {
        
socket_recviSocket szData charsmaxszData ) );
        
        
iStartPos strfindszData "Current IP Address: " );
        
        if ( 
iStartPos != -)
        {
            
iEndPos strfindszData "</body>" );
            
copyg_szServerIP iEndPos - ( iStartPos 20 ) , szDataiStartPos 20 ] );
            
            
socket_closeiSocket );
            
remove_taskTASK_GETIP );
            
            
client_printiRequestPlayer print_chat "* Server IP is [ %s ]" g_szServerIP );
        }
    }
    
    if ( ( 
get_systime() - iRequestTime ) >= )
    {
        
socket_closeiSocket );
        
remove_taskTASK_GETIP );
        
        
client_printiRequestPlayer print_chat "* checkip.dyndns.com failed to respond, unable to obtain IP" );
    }

__________________

Last edited by Bugsy; 10-03-2010 at 00:44.
Bugsy is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:06.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode