IP to Hostname

Discussion in 'Programming' started by twalters84, Oct 3, 2007.

  1. #1
    Hey there,

    I am trying to find a coldfusion method to convert an IP address to a hostname.

    I used to be using the following:

    <cfset inet_address = CreateObject("java", "java.net.InetAddress")>
    <cfset myHostName = inet_address.getByName(cgi.REMOTE_ADDR).getHostName()>

    However, my hosting company recently disabled CreateObject.

    Any suggestions are welcome.

    Sincerely,
    Travis Walters
     
    twalters84, Oct 3, 2007 IP
  2. twalters84

    twalters84 Peon

    Messages:
    514
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hey there,

    I found a solution.

    The only bad part is that the solution is not completely coldfusion.

    <cfhttp method="Get" url="http://www.#myDomain#/getHostname.php?ipAddress=#cgi.REMOTE_ADDR#" resolveurl="Yes">
    <cfset myHostName = '#Trim(cfhttp.FileContent)#'>

    It appears PHP is also enabled on my server. So I was able to create this PHP file from coldfusion:

    <?php
    $hostname = gethostbyaddr($_GET['ipAddress']);
    echo $hostname;
    ?>

    I was just wondering, how come the closing tag </cfhttp> is not needed for the GET variable?

    Sincerely,
    Travis Walters
     
    twalters84, Oct 4, 2007 IP