OVH Cloud OVH Cloud

Adresse IP de mon modem ADSL

3 réponses
Avatar
fabien.perie
Bonjour,

j'ai trouvé le code JAVA suivant : «

InetAddress Ip = InetAddress.getLocalHost();
jTextYourIP.setText("" + Ip.getHostAddress()); »

qui me permet de retrouver l'adresse IP locale de mon PC...
Comment faire pour avoir l'adresse IP que j'utilise pour aller sur
Internet via mon modem ADSL ???

Merci d'avance.

Fabien

3 réponses

Avatar
Johann Burkard
PERIE Fabien wrote:
Comment faire pour avoir l'adresse IP que j'utilise pour aller sur
Internet via mon modem ADSL ???


Tu veux savoir l'addresse IP de ton adapter ou l'addresse IP qui t'est
donné par ton ISP?

Pour l'addresse de ton adapter, regarde java.net.NetworkInterface.

Pour l'addresse public, il te faut probablement écrire un parser pour
ifconfig/ipconfig. J'ai écrit quelque chose comme ca [1] pour UUID [2].

Sur Windows, ipconfig /all me donne:

C:Documents and SettingsAdministrator>ipconfig /all

[...]

Ethernet adapter Intel PRO 1000:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Intel(R) PRO/1000 MTW
Network Connection
Physical Address. . . . . . . . . : [...]
DHCP Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.0.33
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
DNS Servers . . . . . . . . . . . :

PPP adapter T-DSL:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : WAN (PPP/SLIP) Interface
Physical Address. . . . . . . . . : [...]
DHCP Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 84.128.209.33
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 84.128.209.33
DNS Servers . . . . . . . . . . . : 217.237.150.33
217.237.151.161
NetBIOS over Tcpip. . . . . . . . : Disabled

[1] Classe com.eaio.uuid.UUIDGen.
[2] <http://johannburkard.de>

Johann
--
Verschwinden sie endlich in ihren Laufstall und geben Sie ruhe, denn
das, was von ihnen in den letzten Wochen und Monaten zu lesen war, ist
kaum noch an Peinlichkeiten zu ueberbieten.
(*Tönnes über Andere in <a701sh$99p$)

Avatar
Symon
Et sous nunux, il faut tapper "ifconfig ppp0" (en root) si tu utilises
une connexion pppoe (sinon remplacer ppp0 par eth0, eth1, etc...).

Chez moi ça donne ça :

ppp0 Link encap:Point-to-Point Protocol
inet addr:84.98.246.54 P-t-P:84.98.246.1 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1492 Metric:1
RX packets:727734 errors:0 dropped:0 overruns:0 frame:0
TX packets:743768 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:487894647 (465.2 Mb) TX bytes:459025284 (437.7 Mb)

A+

Symon

Johann Burkard wrote:
PERIE Fabien wrote:

Comment faire pour avoir l'adresse IP que j'utilise pour aller sur
Internet via mon modem ADSL ???



Tu veux savoir l'addresse IP de ton adapter ou l'addresse IP qui t'est
donné par ton ISP?

Pour l'addresse de ton adapter, regarde java.net.NetworkInterface.

Pour l'addresse public, il te faut probablement écrire un parser pour
ifconfig/ipconfig. J'ai écrit quelque chose comme ca [1] pour UUID [2].

Sur Windows, ipconfig /all me donne:

C:Documents and SettingsAdministrator>ipconfig /all

[...]

Ethernet adapter Intel PRO 1000:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Intel(R) PRO/1000 MTW
Network Connection
Physical Address. . . . . . . . . : [...]
DHCP Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.0.33
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
DNS Servers . . . . . . . . . . . :

PPP adapter T-DSL:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : WAN (PPP/SLIP) Interface
Physical Address. . . . . . . . . : [...]
DHCP Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 84.128.209.33
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 84.128.209.33
DNS Servers . . . . . . . . . . . : 217.237.150.33
217.237.151.161
NetBIOS over Tcpip. . . . . . . . : Disabled

[1] Classe com.eaio.uuid.UUIDGen.
[2] <http://johannburkard.de>

Johann



Avatar
BJB
Bonjour,
Si tu es dans une config un peu complexe (style PC en DMZ, ou mapping de
port sur un NAT,...), le plus simple est de faire un appel sur
http://checkip.dyndns.org/ et récupérer le résultat ;-)

A+
JB

PERIE Fabien wrote:
Bonjour,

j'ai trouvé le code JAVA suivant : «

InetAddress Ip = InetAddress.getLocalHost();
jTextYourIP.setText("" + Ip.getHostAddress()); »

qui me permet de retrouver l'adresse IP locale de mon PC...
Comment faire pour avoir l'adresse IP que j'utilise pour aller sur
Internet via mon modem ADSL ???

Merci d'avance.

Fabien