Get Private/Public IPv4 Address

If you want to get the IP Address,Subnet Mask,Default Gateway,DHCP Server,Primary WINS Server,Secondary WINS Server then use this snippet:
Code:
const // put this const at the header of the code
    ADAPTERCAPACITY = 4096 // ADAPTERCAPACITY >= 640 * ADAPTERSCOUNT // make sure to count the number of adapters you have at your computer.
   
    IPOFFSETIPADDRESS    = 0x1B0 // Current IP Address
    IPOFFSETSUBNETMASK    = 0x1C0 // Subnet Mask
    IPOFFSETGATEWAY        = 0x1D8 // Default Gateway
    IPOFFSETDHCPSERVER    = 0x1E8 // DHCP Server
    IPOFFSETPWINSS        = 0x200 // Primary WINS Server
    IPOFFSETSWINSS        = 0x210 // Secondary WINS Server
end

const // used by GetMyLocalIP
    ADAPTERLIBRARY                = 31@
    ADAPTERPROC                    = 30@
    ALLADAPTERSINFO                = 29@
    NEXTIPADAPTERINFO            = 28@
    ADAPTERBLOCKSIZEPERINDEX    = 27@
end

// 0AB1: @GetMyLocalIP 3 _adapterindex 0@ _ipoffset 1@ _storetobuffer 2@
// index must be within "0 upto ADAPTERMAXINDEX-1" where ADAPTERMAXINDEX is the number of adapters on your computer
// buffer size must be >= 16
:GetMyLocalIP
if 0AA2: ADAPTERLIBRARY = load_library "Iphlpapi.dll" // IF and SET
then
    if 0AA4: ADAPTERPROC = get_proc_address "GetAdaptersInfo" library ADAPTERLIBRARY // IF and SET
    then
        28@ = 4096
        alloc ALLADAPTERSINFO 28@
        0AA5: call ADAPTERPROC num_params 2 pop 0 28@v ALLADAPTERSINFO // inparams 28@v=buffer size pointer << ALLADAPTERSINFO=buffer pointer

        0085: 11@ = ALLADAPTERSINFO
        0A8D: NEXTIPADAPTERINFO = read_memory 11@ size 4 virtual_protect 0 // get the pointer of the next ip adapter
       
        0085: ADAPTERBLOCKSIZEPERINDEX = NEXTIPADAPTERINFO
        0062: ADAPTERBLOCKSIZEPERINDEX -= 11@

        006A: 0@ *= ADAPTERBLOCKSIZEPERINDEX
        005A: 11@ += 0@  // jump to the specified index then afterwards read that adapter block

        005A: 11@ += 1@  // IP Offset

            // memcpy _source 11@ _destination 0@ _size 16
        2@+=15
        0A8C: write_memory 2@ size 1 value 0 virtual_protect 0 // null terminator
        2@-=15
        for 9@ = 1 to 15
            0A8D: 10@ = read_memory 11@ size 1 virtual_protect 0
            0A8C: write_memory 2@ size 1 value 10@ virtual_protect 0
            if 10@ == 0x0 // null terminator
            then break
            else
                2@++
                11@++
            end
        end
            //

        free ALLADAPTERSINFO
    end
    0AA3: free_library ADAPTERLIBRARY
end
ret 0



Demo:
Code:
alloc 0@ 16

for 1@ = 0 to 5 // in my pc I got 6 adapters with me
    0AB1: @GetMyLocalIP 3 _adapterindex 1@ _ipoffset IPOFFSETIPADDRESS _storetobuffer 0@ // 4th index is my wlan, try getting your own index
    chatmsg "Adapter %d IP: %s" -1 1@ 0@
end

free 0@
Code:
alloc 0@ 16

for 1@ = 0 to 5 // in my pc I got 6 adapters with me
    0AB1: @GetMyLocalIP 3 _adapterindex 1@ _ipoffset IPOFFSETSUBNETMASK _storetobuffer 0@ // 4th index is my wlan, try getting your own index
    chatmsg "Adapter %d Subnet Mask: %s" -1 1@ 0@
end

free 0@
Code:
alloc 0@ 16

for 1@ = 0 to 5 // in my pc I got 6 adapters with me
    0AB1: @GetMyLocalIP 3 _adapterindex 1@ _ipoffset IPOFFSETGATEWAY _storetobuffer 0@ // 4th index is my wlan, try getting your own index
    chatmsg "Adapter %d Default Gateway: %s" -1 1@ 0@
end

free 0@
Code:
alloc 0@ 16

for 1@ = 0 to 5 // in my pc I got 6 adapters with me
    0AB1: @GetMyLocalIP 3 _adapterindex 1@ _ipoffset IPOFFSETDHCPSERVER _storetobuffer 0@ // 4th index is my wlan, try getting your own index
    chatmsg "Adapter %d DHCP Server: %s" -1 1@ 0@
end

free 0@
Code:
alloc 0@ 16

for 1@ = 0 to 5 // in my pc I got 6 adapters with me
    0AB1: @GetMyLocalIP 3 _adapterindex 1@ _ipoffset IPOFFSETPWINSS _storetobuffer 0@ // 4th index is my wlan, try getting your own index
    chatmsg "Adapter %d Primary WINS Server: %s" -1 1@ 0@
end

free 0@
Code:
alloc 0@ 16

for 1@ = 0 to 5 // in my pc I got 6 adapters with me
    0AB1: @GetMyLocalIP 3 _adapterindex 1@ _ipoffset IPOFFSETSWINSS _storetobuffer 0@ // 4th index is my wlan, try getting your own index
    chatmsg "Adapter %d Secondary WINS Server: %s" -1 1@ 0@
end

free 0@
 

Attachments

  • IPOFFSET0x1B0.png
    IPOFFSET0x1B0.png
    1.1 MB · Views: 1,529
  • IPOFFSET0x1C0.png
    IPOFFSET0x1C0.png
    1.1 MB · Views: 76
  • IPOFFSET0x1D8.png
    IPOFFSET0x1D8.png
    1.1 MB · Views: 57
  • IPOFFSET0x1E8.png
    IPOFFSET0x1E8.png
    1.1 MB · Views: 48
  • IPOFFSET0x200.png
    IPOFFSET0x200.png
    1.1 MB · Views: 43
  • IPOFFSET0x210.png
    IPOFFSET0x210.png
    1.1 MB · Views: 48

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
268
Location
Pluto
Get your PUBLIC IP Address:
Code:
// 0AB1: @getmyPublicIP 1 _buffer 0@
// size of 0@ must be >= 16 (nnn.nnn.nnn.nnn/0)
:getmyPublicIP // by ajom
if 0AAB:   file_exists "cleo\temp.html"
then 0B00: delete_file "cleo\temp.html"
end

0AC6: 31@ = label @publicipurl offset
0AC6: 30@ = label @publicipfilename offset
if 0AB1: @downloadURL 2 _fromurl 31@ _toFileName 30@
then
    if 0AAB:   file_exists "cleo\temp.html"
    then
        if 0A9A: 31@ = openfile "cleo\temp.html" mode 0x72
        then
            alloc 30@ 94
            30@+=93
            0A8C: write_memory 30@ size 1 value 0 virtual_protect 0 // null terminator
            30@-=93
          
            0AD7: read_string_from_file 31@ to 30@ size 93

            0085: 29@ = 30@
            29@ += 76  // snippet by ajom
            if 0AB1: @strchr 2 _String 29@ _asciichar 60 _storepointer 28@ // find char '<'
            then
                0A8C: write_memory 28@ size 1 value 0 virtual_protect 0 // null terminator
                0AB1: @strcpy 2 _destination 0@ _source 29@
            end
          
            free 30@
            0A9B: closefile 31@
        end
        0B00: delete_file "cleo\temp.html"
    end
end
ret 0
:publicipurl
hex
    "http://checkip.dyndns.org/\0"
end
:publicipfilename
hex
    "cleo\\temp.html\0"
end

// 0AB1: @strchr 2 _string 0@ _asciichar 1@ _storepointer 31@
:strchr // by ajom
while true
    0A8D: 31@ = read_memory 0@ size 1 virtual_protect 0
    if  003B:   1@ == 31@  // same character
    then
        0485:  return_true
        ret 1 0@
        break
    else
        if 31@ == 0 // a null terminator
        then break
        else 0@++
        end
    end
end
059A:  return_false
ret 1 0@

// 0AB1: @strcpy 2 _destination 0@ _source 1@
:strcpy // by ajom
repeat
    0A8D: 31@ = read_memory 1@ size 1 virtual_protect 0
    0A8C: write_memory 0@ size 1 value 31@ virtual_protect 0
    0@++
    1@++
until 31@ == 0 // null terminator
ret 0

// 0AB1: @downloadURL 2 _fromurl 0@ _toFileName 1@
:downloadURL // by ajom
if 0AA2: 31@ = load_library "Urlmon.dll"
then
    if 0AA4: 30@ = get_proc_address "URLDownloadToFileA" library 31@
    then
        // _lpfnCB = IBindStatusCallback ~ If this has a value of 0(NULL), then GTA SA will freeze during download. I don't know how to create this object in order to make the download asynchrnous. Maybe somebody can make it
        0AA7: call_function 30@ num_params 5 pop 0 _lpfnCB 0 _dwReserved 0 _szFileName 1@ _szURL 0@ _pCaller 0 _returncode 29@  // by ajom
        if 29@ == 0 // code_OK
        then
            0AA3: free_library 31@
            0485:  return_true
            ret 0
        end
    end
    0AA3: free_library 31@
end
059A:  return_false
ret 0

Issues:
  1. Freeze GTA SA during Download Process, this is because I used a NULL IBindStatusCallback. I don't know how to do this binding thing, maybe somebody can improve this snippet.
    • What If I losses connection? The URLDownloadToFileA API Function automatically stops if the download is interrupted. So the game will not freeze forever.

Demo:
Code:
alloc 0@ 16
0AB1: @getmyPublicIP 1 _buffer 0@
0AD1: show_formatted_text_highpriority "Public IP:~n~%s" time 10000 0@
free 0@
 

Attachments

  • 1599808082206.png
    1599808082206.png
    1.3 MB · Views: 40
Last edited:

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
268
Location
Pluto

mpol77

Active member
Joined
Oct 24, 2018
Messages
66
Reaction score
6
awesome tbh
was this meant to work under 0.3DL though?
 
Top