Raised This Month: $ Target: $400
 0% 

Getting Server IP


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 06-17-2009 , 07:55   Re: Getting Server IP
Reply With Quote #5

This is good if you have static ip, but if you have dynamic ip like me, then you can use something like this:
PHP Code:
#include <amxmodx>
#include <sockets>

new g_ip[32]
new 
g_socket

public plugin_init(){
    
register_plugin("Get server ip""1.0""Sylwester")
    
register_clcmd("say ip""get_server_ip")
}


public 
get_server_ip(id){
    new 
error
    
if(g_socket>0){
        
client_print(idprint_chat"Error: socket is in use")
        return 
PLUGIN_HANDLED
    
}

    
g_socket socket_open("www.whatsmyip.org"80SOCKET_TCPerror)
    if(
g_socket 0){
        
socket_send(g_socket"GET / HTTP/1.1^nHost: www.whatsmyip.org^n^n"64)
        
client_print(idprint_chat"Sending request...")
        
set_task(0.1"recv"id)
    }else{
        
client_print(idprint_chat"Socket error")
    }

    return 
PLUGIN_HANDLED
}


public 
recv(id){
    if(!
socket_change(g_socket100))
        
set_task(0.1"recv"id)
    else{
        new 
data[512], ipos
        socket_recv
(g_socketdata511)
        
pos containi(data"Your IP is ")
        if(
pos>-1){
            
pos += 11
            
while(data[pos+i]=='.' || (data[pos+i]>='0' && data[pos+i]<='9')){
                
g_ip[i] = data[pos+i
                
i++
            }
            
client_print(idprint_chat"Server ip: %s"g_ip)
        }
        
socket_close(g_socket)
        
g_socket 0
    
}

My plugin connects to one of the "what is my ip" websites and gets your ip. It will work as long as the website is online, the way it displays ip is not changed and you are not banned because of sending requests too often
If you have your own website you could use it for this plugin. Just make script that displays only ip on whole page (like www.whatismyip.org but that one is down for me now so I used other) and modify this plugin.
__________________
Impossible is Nothing
Sylwester 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 15:38.


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