Raised This Month: $ Target: $400
 0% 

Getting Server IP


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Empowers
BANNED
Join Date: Feb 2009
Location: Ukraine
Old 06-17-2009 , 03:34   Getting Server IP
Reply With Quote #1

I have 2 server ip-s. LAN ip(inside ip) and INTERNET ip(outside ip). I wanna to get INTERNET IP.
But when I do this:
PHP Code:
get_user_ip(0,ip,15
it gives me LAN Ip.

Any suggsetions?
Empowers is offline
Send a message via ICQ to Empowers
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 06-17-2009 , 03:37   Re: Getting Server IP
Reply With Quote #2

Just because you are running on lan, what you wanted to get more...
__________________
xPaw is offline
Empowers
BANNED
Join Date: Feb 2009
Location: Ukraine
Old 06-17-2009 , 03:39   Re: Getting Server IP
Reply With Quote #3

I'm running internet game. But players from LAN can connect to my server throught other ip.

P.s I have sv_lan 0

Understand me?
Empowers is offline
Send a message via ICQ to Empowers
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 06-17-2009 , 06:49   Re: Getting Server IP
Reply With Quote #4

You can try this.
Code:
// No port new szIP[16]; get_cvar_string("ip", szIP, 15);   // With port new szIP[22], szPort[6]; get_cvar_string("ip", szIP, 15); get_cvar_string("port", szPort, 5); format(szIP, 21, "%s:%s", szIP, szPort);
__________________
hleV is offline
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
Mlk27
Veteran Member
Join Date: May 2008
Old 06-17-2009 , 08:24   Re: Getting Server IP
Reply With Quote #6

Query from checkip.dyndns.com much better
Mlk27 is offline
xtinct
Senior Member
Join Date: Jan 2010
Location: http://tekxtinct.ning.co
Old 04-21-2010 , 07:01   Re: Getting Server IP
Reply With Quote #7

Quote:
Originally Posted by Mlk27
Query from checkip.dyndns.com much better
There are then such lots of options, however We need to choose the efiicient and faster one.
__________________
Sorry If I Hurt! Orpheu

1 crab has been found and delivered my me.
xtinct is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 04-21-2010 , 15:37   Re: Getting Server IP
Reply With Quote #8

Quote:
Originally Posted by Sylwester View Post
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.
When writing ip in my server with this running the server crashes and gives me 4 errors from WC3FT.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 04-22-2010 , 11:15   Re: Getting Server IP
Reply With Quote #9

I'm not surprised that it's not working (content received from that website obviously changed), though I don't know why does your server crash when using this plugin. If you got some errors then why didn't you post them?

You can try this version. It works for me now:

PHP Code:
#include <amxmodx>
#include <sockets>

new g_ip[16]
new 
bool:g_got_ip
new g_socket

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


public 
update_ip(){
    static 
error
    
if(g_socket>0){
        
log_amx("Error occurred while trying to retrieve server ip (socket is in use).")
        return
    }
    
    
//send http request to selected host
    
g_socket socket_open("checkip.dyndns.com"80SOCKET_TCPerror)
    if(
g_socket 0){
        
socket_send(g_socket"GET / HTTP/1.1^nHost: checkip.dyndns.com^n^n"64)
        
set_task(0.1"recv")
    }else{
        
log_amx("Error occurred while trying to retrieve server ip (%d)."error)
    }
}


public 
recv(id){
    if(!
socket_change(g_socket1))
        
set_task(0.1"recv"id)
    else{
        new 
data[256], ijdpos
        socket_recv
(g_socketdata255)

        
//analyze data retrieved from website
        
pos containi(data"<body>Current IP Address: ")
        if(
pos>-1){
            
pos += 26
            
while('0' <= data[pos+i] <= '9'){
                
g_ip[i] = data[pos+i]
                
i++
                if(
data[pos+i]=='.'){
                    
g_ip[i] = data[pos+i]
                    
j=++i
                    d
++
                }
            }
            if(
j==|| d!=3){
                
g_got_ip false
            
}else{
                
g_got_ip true
            
}
        }else{
            
g_got_ip false
        
}
        
socket_close(g_socket)
        
g_socket 0
    
}
}


public 
get_server_ip(id){
    if(!
g_got_ip){
        
client_print(idprint_chat"Server was unable to retrieve its external ip")
        return
    }
    
client_print(idprint_chat"Server external ip: %s"g_ip)


__________________
Impossible is Nothing
Sylwester is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 04-22-2010 , 19:52   Re: Getting Server IP
Reply With Quote #10

Sorry for not posting the errors, but I closed the server again before copying them. What happened was I got 4 errors from WC3FT when typing ip. After that I got "Program is not responding" from windows. I try the other thing you posted tomorrow.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
Reply



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